add examples for services

This commit is contained in:
Alexander Nozik 2024-12-12 20:52:51 +03:00
parent 598e1c931c
commit b7279b55c2

View File

@ -36,6 +36,9 @@ fun CoroutineScope.launchPriceUpdate(
): Job = launch {
val cache = ArrayDeque<Pair<Instant, BigDecimal>>()
//restore from db
val now = Clock.System.now()
cache.addAll(db.restorePrice((now-duration)..now))
//read job
launch {
@ -61,7 +64,7 @@ fun CoroutineScope.launchPriceUpdate(
//cache cleanup job
launch {
while (isActive) {
delay(1.minutes)
delay(10.minutes)
val now = Clock.System.now()
cache.removeIf { now - it.first > duration }
}