commit dd72cef18d93550605d7e3aa9346b6f2657c8a7f
parent 01c8396ceb1b96d23cc232d4384f9ede2ce85876
Author: MS <ms@taler.net>
Date: Fri, 29 May 2020 16:33:34 +0200
periodic scheduler skeleton
Diffstat:
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -56,6 +56,8 @@ import io.ktor.server.netty.Netty
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.jvm.javaio.toByteReadChannel
import io.ktor.utils.io.jvm.javaio.toInputStream
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.time.delay
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.transactions.transaction
import org.slf4j.Logger
@@ -66,6 +68,7 @@ import tech.libeufin.util.CryptoUtil.hashpw
import tech.libeufin.util.ebics_h004.HTDResponseOrderData
import java.lang.NumberFormatException
import java.net.URLEncoder
+import java.time.Duration
import java.util.*
import java.util.zip.InflaterInputStream
import javax.crypto.EncryptedPrivateKeyInfo
@@ -240,18 +243,29 @@ fun ApplicationRequest.hasBody(): Boolean {
return false
}
+
+suspend fun schedulePeriodicWork() {
+ while (true) {
+ delay(Duration.ofSeconds(1))
+ // download TWG C52
+ // ingest TWG new histories
+ logger.debug("I am scheduled")
+ }
+}
+
fun serverMain(dbName: String) {
dbCreateTables(dbName)
val client = HttpClient {
expectSuccess = false // this way, it does not throw exceptions on != 200 responses.
}
val server = embeddedServer(Netty, port = 5001) {
-
+ launch {
+ schedulePeriodicWork()
+ }
install(CallLogging) {
this.level = Level.DEBUG
this.logger = tech.libeufin.nexus.logger
}
-
install(ContentNegotiation) {
jackson {
enable(SerializationFeature.INDENT_OUTPUT)