diff options
author | MS <ms@taler.net> | 2021-01-11 21:37:35 +0100 |
---|---|---|
committer | MS <ms@taler.net> | 2021-01-29 10:54:07 +0100 |
commit | 0007b25ceb408617ffcdbb2a40828e51d601dc73 (patch) | |
tree | 50c3b0d4c3a72f78acbb3bd59c1033ec05d76b14 | |
parent | 356314701a0d447259dc5d4624e2d2d17154d8a5 (diff) | |
download | libeufin-0007b25ceb408617ffcdbb2a40828e51d601dc73.tar.gz libeufin-0007b25ceb408617ffcdbb2a40828e51d601dc73.tar.bz2 libeufin-0007b25ceb408617ffcdbb2a40828e51d601dc73.zip |
Allow setting the time via HTTP API.
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/Scheduling.kt | 3 | ||||
-rw-r--r-- | sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt | 8 | ||||
-rw-r--r-- | sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 22 | ||||
-rw-r--r-- | util/src/main/kotlin/time.kt | 14 |
4 files changed, 39 insertions, 8 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Scheduling.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Scheduling.kt index 51f5285c..8eff8790 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/Scheduling.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Scheduling.kt @@ -102,7 +102,6 @@ fun startOperationScheduler(httpClient: HttpClient) { GlobalScope.launch { while (true) { logger.trace("running schedule loop") - // First, assign next execution time stamps to all tasks that need them transaction { NexusScheduledTaskEntity.find { @@ -145,8 +144,6 @@ fun startOperationScheduler(httpClient: HttpClient) { } } } - - // Wait a bit delay(Duration.ofMillis(tick)) } } diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt index c7f906c8..8d602d1b 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt @@ -110,3 +110,11 @@ data class BankAccountReport( var creationTime: Long, val message: String ) + +data class LibeufinRelativeTime( + val rel: Long +) + +data class LibeufinAbsoluteTime( + val abs: Long +)
\ No newline at end of file diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt index 484888d9..1948f984 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -54,7 +54,6 @@ import com.fasterxml.jackson.databind.exc.MismatchedInputException import com.fasterxml.jackson.module.kotlin.KotlinModule import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException import org.jetbrains.exposed.sql.statements.api.ExposedBlob -import java.time.Instant import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.core.context import com.github.ajalt.clikt.core.subcommands @@ -85,6 +84,10 @@ import tech.libeufin.util.ebics_h004.EbicsResponse import tech.libeufin.util.ebics_h004.EbicsTypes import java.net.BindException import java.util.* +import java.time.Duration +import java.time.Instant +import java.time.ZoneId +import java.time.ZonedDateTime import kotlin.random.Random import kotlin.system.exitProcess @@ -292,6 +295,7 @@ fun serverMain(dbName: String, port: Int) { get("/") { call.respondText("Hello, this is Sandbox\n", ContentType.Text.Plain) } + get("/config") { call.respond(object { val name = "libeufin-sandbox" @@ -300,6 +304,22 @@ fun serverMain(dbName: String, port: Int) { val version = "0.0.0-dev.0" }) } + + post("/admin/time/set-relative") { + val body = call.receive<LibeufinRelativeTime>() + val d = Duration.ofSeconds(body.rel) + setClock(d) + call.respond(object {}) + return@post + } + + post("/admin/time/set-absolute") { + val body = call.receive<LibeufinAbsoluteTime>() + setClock(importZonedDateFromSecond(body.abs)) + call.respond(object {}) + return@post + } + // only reason for a post is to hide the iban (to some degree.) post("/admin/payments/camt") { val body = call.receiveJson<CamtParams>() diff --git a/util/src/main/kotlin/time.kt b/util/src/main/kotlin/time.kt index dcf1ab75..d90c921d 100644 --- a/util/src/main/kotlin/time.kt +++ b/util/src/main/kotlin/time.kt @@ -24,6 +24,9 @@ import java.time.format.DateTimeFormatter private var LIBEUFIN_CLOCK = Clock.system(ZoneId.systemDefault()) +fun setClock(abs: ZonedDateTime) { + LIBEUFIN_CLOCK = Clock.fixed(abs.toInstant(), abs.zone) +} fun setClock(rel: Duration) { LIBEUFIN_CLOCK = Clock.offset(LIBEUFIN_CLOCK, rel) } @@ -32,10 +35,6 @@ fun getNow(): ZonedDateTime { return ZonedDateTime.now(LIBEUFIN_CLOCK) } -fun getNow(zone: ZoneId): ZonedDateTime { - return ZonedDateTime.now(zone) -} - fun ZonedDateTime.toZonedString(): String { return this.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) } @@ -50,6 +49,13 @@ fun dashedDateToZonedDateTime(date: String): ZonedDateTime { return asLocalDate.atStartOfDay(ZoneId.systemDefault()) } +fun importZonedDateFromSecond(second: Long): ZonedDateTime { + return ZonedDateTime.ofInstant( + Instant.ofEpochSecond(second), + ZoneId.systemDefault() + ) +} + fun importZonedDateFromMillis(millis: Long): ZonedDateTime { return ZonedDateTime.ofInstant( Instant.ofEpochMilli(millis), |