logging
This commit is contained in:
parent
5d108a2781
commit
a794d1d074
2 changed files with 10 additions and 4 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
package observer.nelle.nelleObserverBackend
|
package observer.nelle.nelleObserverBackend
|
||||||
|
|
||||||
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import io.ktor.client.engine.cio.*
|
import io.ktor.client.engine.cio.*
|
||||||
import io.ktor.client.plugins.auth.*
|
import io.ktor.client.plugins.auth.*
|
||||||
|
@ -14,6 +15,8 @@ import io.ktor.server.plugins.cors.routing.*
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import observer.nelle.nelleObserverBackend.plugins.configureRouting
|
import observer.nelle.nelleObserverBackend.plugins.configureRouting
|
||||||
|
|
||||||
|
val logger = KotlinLogging.logger("karizzma")
|
||||||
|
|
||||||
fun main(args: Array<String>): Unit = EngineMain.main(args)
|
fun main(args: Array<String>): Unit = EngineMain.main(args)
|
||||||
|
|
||||||
fun Application.module() {
|
fun Application.module() {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import io.ktor.server.response.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
import observer.nelle.nelleObserverBackend.Config
|
import observer.nelle.nelleObserverBackend.Config
|
||||||
import observer.nelle.nelleObserverBackend.getMeow
|
import observer.nelle.nelleObserverBackend.getMeow
|
||||||
|
import observer.nelle.nelleObserverBackend.logger
|
||||||
import observer.nelle.nelleObserverBackend.makePost
|
import observer.nelle.nelleObserverBackend.makePost
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.concurrent.timerTask
|
import kotlin.concurrent.timerTask
|
||||||
|
@ -18,11 +19,10 @@ var meowTimedOut = false
|
||||||
|
|
||||||
fun meowTimer() {
|
fun meowTimer() {
|
||||||
meowTimedOut = true
|
meowTimedOut = true
|
||||||
println("timed out")
|
|
||||||
Timer("SettingUp", true).schedule(
|
Timer("SettingUp", true).schedule(
|
||||||
timerTask {
|
timerTask {
|
||||||
meowTimedOut = false
|
meowTimedOut = false
|
||||||
println("not timed out")
|
logger.debug { "timeout reset" }
|
||||||
},
|
},
|
||||||
// 33 minutes in milliseconds
|
// 33 minutes in milliseconds
|
||||||
1980000,
|
1980000,
|
||||||
|
@ -36,10 +36,12 @@ 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" }
|
||||||
}
|
}
|
||||||
if (!meowTimedOut) {
|
if (!meowTimedOut) {
|
||||||
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")
|
||||||
|
logger.debug { "not timed out" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,18 +50,19 @@ fun Application.configureRouting(client: HttpClient) {
|
||||||
post("/meow") {
|
post("/meow") {
|
||||||
if (call.receiveText() == Config().superSecret) {
|
if (call.receiveText() == Config().superSecret) {
|
||||||
call.response.status(HttpStatusCode(201, "Meow Posted"))
|
call.response.status(HttpStatusCode(201, "Meow Posted"))
|
||||||
println("secret code received, bypassing timeout")
|
|
||||||
makePost(client, getMeow(), Config().instanceDomain)
|
makePost(client, getMeow(), Config().instanceDomain)
|
||||||
println("meow sent!")
|
logger.debug { "meowed with bypass" }
|
||||||
} 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...")
|
||||||
|
logger.debug { "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!")
|
||||||
|
logger.debug { "meowed" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue