diff options
author | Antoine A <> | 2024-03-20 18:33:45 +0100 |
---|---|---|
committer | Antoine A <> | 2024-03-20 18:33:45 +0100 |
commit | a46b61bec3e670422fe8e84db44c07f80272495b (patch) | |
tree | a12c8b7a2ac2c9d5f50668a57a95a37db0bb5548 /nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt | |
parent | a047fb5c1076c0afe2c04c8beb2edd6026f595b3 (diff) | |
download | libeufin-a46b61bec3e670422fe8e84db44c07f80272495b.tar.gz libeufin-a46b61bec3e670422fe8e84db44c07f80272495b.tar.bz2 libeufin-a46b61bec3e670422fe8e84db44c07f80272495b.zip |
Share duration parsing with libeufin-nexus
Diffstat (limited to 'nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt')
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt index 47c021cd..298d84b4 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt @@ -32,10 +32,12 @@ import tech.libeufin.nexus.db.* import java.io.IOException import java.io.InputStream import java.time.Instant +import java.time.Duration import java.time.LocalDate import java.time.ZoneId import kotlin.io.* import kotlin.io.path.* +import kotlin.time.toKotlinDuration /** * Necessary data to perform a download. @@ -389,20 +391,16 @@ class EbicsFetch: CliktCommand("Fetches EBICS files") { throw Exception("Failed to fetch documents") } } 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) { + var frequency: Duration = cfg.config.requireDuration("nexus-fetch", "frequency") + val raw = cfg.config.requireString("nexus-fetch", "frequency") + logger.debug("Running with a frequency of $raw") + if (frequency == Duration.ZERO) { logger.warn("Long-polling not implemented, running therefore in transient mode") - null - } else { - cfgFrequency } do { fetchDocuments(db, ctx, docs) - delay(((frequency?.inSeconds ?: 0) * 1000).toLong()) - } while (frequency != null) + delay(frequency.toKotlinDuration()) + } while (frequency != Duration.ZERO) } } } |