From b7279b55c2b69b843704f5715dee1bf084bad033 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 12 Dec 2024 20:52:51 +0300 Subject: [PATCH] add examples for services --- src/main/kotlin/microservice/pricingService.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/microservice/pricingService.kt b/src/main/kotlin/microservice/pricingService.kt index 1944cb6..a0a8f20 100644 --- a/src/main/kotlin/microservice/pricingService.kt +++ b/src/main/kotlin/microservice/pricingService.kt @@ -36,6 +36,9 @@ fun CoroutineScope.launchPriceUpdate( ): Job = launch { val cache = ArrayDeque>() + //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 } }