aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine A <>2024-01-13 14:06:09 +0000
committerAntoine A <>2024-01-13 14:06:09 +0000
commitaa807728a3c02127db34bfbc7229313d4f53556f (patch)
tree7101d0631d9e0313ed76291006b5061b796fb268
parentfe4c49c5444b6033e23bc31bebeb2407d61452c1 (diff)
downloadlibeufin-aa807728a3c02127db34bfbc7229313d4f53556f.tar.gz
libeufin-aa807728a3c02127db34bfbc7229313d4f53556f.tar.bz2
libeufin-aa807728a3c02127db34bfbc7229313d4f53556f.zip
Fix non transient ebics commands
-rw-r--r--integration/conf/netzbon.conf2
-rw-r--r--integration/conf/postfinance.conf2
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt38
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt41
4 files changed, 42 insertions, 41 deletions
diff --git a/integration/conf/netzbon.conf b/integration/conf/netzbon.conf
index 2ffbcd85..1fa31c1f 100644
--- a/integration/conf/netzbon.conf
+++ b/integration/conf/netzbon.conf
@@ -19,9 +19,11 @@ BIC = POFICHBEXXX
NAME = Genossenschaft Netz Soziale Oekonomie
[nexus-fetch]
+FREQUENCY = 5s
STATEMENT_LOG_DIRECTORY = test/netzbon/fetch
[nexus-submit]
+FREQUENCY = 5s
SUBMISSIONS_LOG_DIRECTORY = test/netzbon/submit
[nexus-postgres]
diff --git a/integration/conf/postfinance.conf b/integration/conf/postfinance.conf
index 0715b682..ece6469c 100644
--- a/integration/conf/postfinance.conf
+++ b/integration/conf/postfinance.conf
@@ -18,9 +18,11 @@ CLIENT_PRIVATE_KEYS_FILE = test/postfinance/client-keys.json
IBAN = CH7789144474425692816
[nexus-fetch]
+FREQUENCY = 5s
STATEMENT_LOG_DIRECTORY = test/postfinance/fetch
[nexus-submit]
+FREQUENCY = 5s
SUBMISSIONS_LOG_DIRECTORY = test/postfinance/submit
[nexus-postgres]
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
index d87555fb..0697cd67 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
@@ -4,7 +4,7 @@ import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.groups.*
import io.ktor.client.*
-import kotlinx.coroutines.runBlocking
+import kotlinx.coroutines.*
import net.taler.wallet.crypto.Base32Crockford
import net.taler.wallet.crypto.EncodingException
import tech.libeufin.nexus.ebics.*
@@ -17,7 +17,6 @@ import java.time.Instant
import java.time.LocalDate
import java.time.ZoneId
import java.util.UUID
-import kotlin.concurrent.fixedRateTimer
import kotlin.io.path.*
/**
@@ -554,28 +553,25 @@ class EbicsFetch: CliktCommand("Fetches bank records. Defaults to camt.054 noti
runBlocking {
fetchDocuments(db, ctx)
}
- return@cliCmd
- }
- val configValue = cfg.config.requireString("nexus-fetch", "frequency")
- val frequencySeconds = checkFrequency(configValue)
- val frequency: NexusFrequency = NexusFrequency(frequencySeconds, configValue)
- logger.debug("Running with a frequency of ${frequency.fromConfig}")
- if (frequency.inSeconds == 0) {
- logger.warn("Long-polling not implemented, running therefore in transient mode")
- runBlocking {
- fetchDocuments(db, ctx)
+ } else {
+ val configValue = cfg.config.requireString("nexus-fetch", "frequency")
+ val frequencySeconds = checkFrequency(configValue)
+ val cfgFrequency: NexusFrequency = NexusFrequency(frequencySeconds, configValue)
+ logger.debug("Running with a frequency of ${cfgFrequency.fromConfig}")
+ val frequency: NexusFrequency? = if (cfgFrequency.inSeconds == 0) {
+ logger.warn("Long-polling not implemented, running therefore in transient mode")
+ null
+ } else {
+ cfgFrequency
}
- return@cliCmd
- }
- fixedRateTimer(
- name = "ebics submit period",
- period = (frequency.inSeconds * 1000).toLong(),
- action = {
- runBlocking {
+ runBlocking {
+ do {
+ // TODO error handling
fetchDocuments(db, ctx)
- }
+ delay(((frequency?.inSeconds ?: 0) * 1000).toLong())
+ } while (frequency != null)
}
- )
+ }
}
}
}
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt
index a7ddfed3..1e691099 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt
@@ -23,7 +23,7 @@ import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.groups.*
import io.ktor.client.*
-import kotlinx.coroutines.runBlocking
+import kotlinx.coroutines.*
import tech.libeufin.nexus.ebics.EbicsSideError
import tech.libeufin.nexus.ebics.EbicsSideException
import tech.libeufin.nexus.ebics.EbicsUploadException
@@ -35,7 +35,6 @@ import java.time.Instant
import java.time.LocalDate
import java.time.ZoneId
import java.util.*
-import kotlin.concurrent.fixedRateTimer
import kotlin.io.path.createDirectories
import kotlin.io.path.*
@@ -294,27 +293,29 @@ class EbicsSubmit : CliktCommand("Submits any initiated payment found in the dat
return@cliCmd
}
Database(dbCfg.dbConnStr).use { db ->
- if (transient) {
+ val frequency = if (transient) {
logger.info("Transient mode: submitting what found and returning.")
- submitBatch(ctx, db)
- return@cliCmd
- }
- val configValue = cfg.config.requireString("nexus-submit", "frequency")
- val frequencySeconds = checkFrequency(configValue)
- val frequency: NexusFrequency = NexusFrequency(frequencySeconds, configValue)
- logger.debug("Running with a frequency of ${frequency.fromConfig}")
- if (frequency.inSeconds == 0) {
- logger.warn("Long-polling not implemented, running therefore in transient mode")
- submitBatch(ctx, db)
- return@cliCmd
+ null
+ } else {
+ val configValue = cfg.config.requireString("nexus-submit", "frequency")
+ val frequencySeconds = checkFrequency(configValue)
+ val frequency: NexusFrequency = NexusFrequency(frequencySeconds, configValue)
+ logger.debug("Running with a frequency of ${frequency.fromConfig}")
+ if (frequency.inSeconds == 0) {
+ logger.warn("Long-polling not implemented, running therefore in transient mode")
+ null
+ } else {
+ frequency
+ }
}
- fixedRateTimer(
- name = "ebics submit period",
- period = (frequency.inSeconds * 1000).toLong(),
- action = {
+ runBlocking {
+ do {
+ // TODO error handling
submitBatch(ctx, db)
- }
- )
+ // TODO take submitBatch taken time in the delay
+ delay(((frequency?.inSeconds ?: 0) * 1000).toLong())
+ } while (frequency != null)
+ }
}
}
} \ No newline at end of file