gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] 01/01: continuing with the scheduling API


From: gnunet
Subject: [libeufin] 01/01: continuing with the scheduling API
Date: Mon, 07 Dec 2020 16:49:17 +0100

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

commit 785140724e8305d1e962d6140d10b2684bc464d3
Author: MS <ms@taler.net>
AuthorDate: Mon Dec 7 16:38:54 2020 +0100

    continuing with the scheduling API
---
 .../main/kotlin/tech/libeufin/nexus/server/JSON.kt | 14 ++++++
 .../tech/libeufin/nexus/server/NexusServer.kt      | 53 +++++++++++++++++++++-
 2 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
index ecd4854..b2d8e72 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
@@ -32,6 +32,8 @@ import 
com.fasterxml.jackson.databind.annotation.JsonDeserialize
 import com.fasterxml.jackson.databind.annotation.JsonSerialize
 import com.fasterxml.jackson.databind.deser.std.StdDeserializer
 import com.fasterxml.jackson.databind.ser.std.StdSerializer
+import tech.libeufin.nexus.NexusScheduledTasksTable
+import tech.libeufin.nexus.NexusScheduledTasksTable.nullable
 import tech.libeufin.nexus.iso20022.CamtBankAccountEntry
 import tech.libeufin.nexus.iso20022.CreditDebitIndicator
 import tech.libeufin.nexus.iso20022.EntryStatus
@@ -339,6 +341,18 @@ data class Pain001Data(
     val subject: String
 )
 
+data class AccountTask(
+    val resourceType: String,
+    val resourceId: String,
+    val taskName: String,
+    val taskType: String,
+    val taskCronspec: String,
+    val taskParams: String,
+    val nextScheduledExecutionSec: Long?, // human-readable time (= Epoch when 
this value doesn't exist in DB)
+    val prevScheduledExecutionSec: Long? // human-readable time (= Epoch when 
this value doesn't exist in DB)
+)
+
+
 data class CreateAccountTaskRequest(
     val name: String,
     val cronspec: String,
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
index 13278cd..64e6640 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -78,7 +78,14 @@ fun ensureNonNull(param: String?): String {
 fun ensureLong(param: String?): Long {
     val asString = ensureNonNull(param)
     return asString.toLongOrNull() ?: throw NexusError(
-        HttpStatusCode.BadRequest, "Parameter is not a number: ${param}"
+        HttpStatusCode.BadRequest, "Parameter is not Long: ${param}"
+    )
+}
+
+fun ensureInt(param: String?): Int {
+    val asString = ensureNonNull(param)
+    return asString.toIntOrNull() ?: throw NexusError(
+        HttpStatusCode.BadRequest, "Parameter is not Int: ${param}"
     )
 }
 
@@ -412,6 +419,29 @@ fun serverMain(dbName: String, host: String) {
                 call.respond(resp)
             }
 
+            // Get all the scheduled jobs to the requester.
+            get("/bank-accounts/{accountid}/schedule") {
+                val ret = mutableListOf<AccountTask>()
+                transaction {
+                    NexusScheduledTaskEntity.all().forEach {
+                        ret.add(
+                            AccountTask(
+                                resourceType = it.resourceType,
+                                resourceId = it.resourceId,
+                                taskName = it.taskName,
+                                taskType = it.taskType,
+                                taskCronspec = it.taskCronspec,
+                                taskParams = it.taskParams,
+                                nextScheduledExecutionSec = 
it.nextScheduledExecutionSec,
+                                prevScheduledExecutionSec = 
it.prevScheduledExecutionSec
+                            )
+                        )
+                    }
+                }
+                call.respond(ret)
+                return@get
+            }
+
             post("/bank-accounts/{accountid}/schedule") {
                 val schedSpec = call.receive<CreateAccountTaskRequest>()
                 val accountId = ensureNonNull(call.parameters["accountid"])
@@ -459,7 +489,26 @@ fun serverMain(dbName: String, host: String) {
             }
 
             get("/bank-accounts/{accountId}/schedule/{taskId}") {
-                call.respond(object { })
+                val task = transaction {
+                    
NexusScheduledTaskEntity.findById(ensureInt(call.parameters["taskId"]))
+                }
+                call.respond(
+                    if (task != null) {
+                        AccountTask(
+                            resourceId = task.resourceId,
+                            resourceType = task.resourceType,
+                            taskName = task.taskName,
+                            taskCronspec = task.taskCronspec,
+                            taskType = task.taskType,
+                            taskParams = task.taskParams,
+                            nextScheduledExecutionSec = 
task.nextScheduledExecutionSec,
+                            prevScheduledExecutionSec = 
task.prevScheduledExecutionSec
+                        )
+                    } else {
+                        object {}
+                    }
+                )
+                return@get
             }
 
             delete("/bank-accounts/{accountId}/schedule/{taskId}") {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]