Randomized timeout time
This commit is contained in:
parent
bdd010ef7e
commit
5626ff054c
2 changed files with 12 additions and 6 deletions
|
@ -18,22 +18,26 @@ import kotlin.time.Duration.Companion.minutes
|
||||||
|
|
||||||
var meowTimedOut = false
|
var meowTimedOut = false
|
||||||
var beepTimedOut = false
|
var beepTimedOut = false
|
||||||
var timeoutTime = 33.minutes
|
|
||||||
|
|
||||||
|
// function to facilitate the timeout for meows
|
||||||
fun meowTimer() {
|
fun meowTimer() {
|
||||||
meowTimedOut = true
|
meowTimedOut = true
|
||||||
|
// get the randomized timeout time, anywhere between
|
||||||
|
val timeoutTime = (10..180).random().minutes
|
||||||
|
println(timeoutTime)
|
||||||
Timer("SettingUp", true).schedule(
|
Timer("SettingUp", true).schedule(
|
||||||
timerTask {
|
timerTask {
|
||||||
meowTimedOut = false
|
meowTimedOut = false
|
||||||
logger.debug { "timeout reset" }
|
logger.debug { "timeout reset" }
|
||||||
},
|
},
|
||||||
// 33 minutes in milliseconds
|
|
||||||
timeoutTime.inWholeMilliseconds,
|
timeoutTime.inWholeMilliseconds,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// same as meowTimer, but for beeps
|
||||||
fun beepTimer() {
|
fun beepTimer() {
|
||||||
beepTimedOut = true
|
beepTimedOut = true
|
||||||
|
val timeoutTime = (1..1440).random().minutes
|
||||||
Timer("SettingUp", true).schedule(
|
Timer("SettingUp", true).schedule(
|
||||||
timerTask {
|
timerTask {
|
||||||
beepTimedOut = false
|
beepTimedOut = false
|
||||||
|
@ -44,9 +48,11 @@ fun beepTimer() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this is where the fun REST comes in!
|
||||||
fun Application.configureRouting(client: HttpClient) {
|
fun Application.configureRouting(client: HttpClient) {
|
||||||
routing {
|
routing {
|
||||||
rateLimit {
|
rateLimit {
|
||||||
|
// route all paths of */api
|
||||||
route("/api") {
|
route("/api") {
|
||||||
// meow
|
// meow
|
||||||
route("/meow") {
|
route("/meow") {
|
||||||
|
@ -55,7 +61,7 @@ fun Application.configureRouting(client: HttpClient) {
|
||||||
if (meowTimedOut) {
|
if (meowTimedOut) {
|
||||||
call.response.status(HttpStatusCode(423, "Timed Out"))
|
call.response.status(HttpStatusCode(423, "Timed Out"))
|
||||||
call.respondText("Timed Out")
|
call.respondText("Timed Out")
|
||||||
logger.debug { "timed out" }
|
logger.debug { "timed out for some time" }
|
||||||
} else {
|
} else {
|
||||||
call.response.status(HttpStatusCode(100, "Not Timed Out"))
|
call.response.status(HttpStatusCode(100, "Not Timed Out"))
|
||||||
call.respondText("Not Timed Out")
|
call.respondText("Not Timed Out")
|
||||||
|
@ -72,13 +78,13 @@ fun Application.configureRouting(client: HttpClient) {
|
||||||
} else {
|
} else {
|
||||||
if (meowTimedOut) {
|
if (meowTimedOut) {
|
||||||
call.response.status(HttpStatusCode(423, "Timed Out"))
|
call.response.status(HttpStatusCode(423, "Timed Out"))
|
||||||
call.respondText("still sleeping...")
|
call.respondText("still sleeping... timed out for some time")
|
||||||
logger.info { "failed meow" }
|
logger.info { "failed meow" }
|
||||||
} else {
|
} else {
|
||||||
call.response.status(HttpStatusCode(201, "Meow Posted"))
|
call.response.status(HttpStatusCode(201, "Meow Posted"))
|
||||||
makePost(client, getMeow(), Config().instanceDomain)
|
makePost(client, getMeow(), Config().instanceDomain)
|
||||||
meowTimer()
|
meowTimer()
|
||||||
call.respondText("meow' sent!")
|
call.respondText("meow' sent! timed out for some time")
|
||||||
logger.info { "meowed" }
|
logger.info { "meowed" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<hr>
|
<hr>
|
||||||
<h3>meow/beep </h3>
|
<h3>meow/beep </h3>
|
||||||
<p>press the buttons bellow to make me meow/beep on the fediverse,
|
<p>press the buttons bellow to make me meow/beep on the fediverse,
|
||||||
there is a global timeout of 33 minutes, and a separate timer for each button. if it says its sleeping, come back and try again later!</p>
|
there is a global timeout of anywhere between 10 and 180 minutes, and a separate timer for each button. if it says its sleeping, come back and try again later!</p>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
class="custom-btn btn-1 beep-buttons"
|
class="custom-btn btn-1 beep-buttons"
|
||||||
|
|
Loading…
Reference in a new issue