Log scheduler started with initial delay

This commit is contained in:
Guntis Smaukstelis
2023-05-14 16:08:44 +03:00
parent 6ca1f4a13a
commit bdfc9df0e2
+6 -3
View File
@@ -2,6 +2,7 @@ package server
import cats.effect._ import cats.effect._
import cats.effect.unsafe.implicits.global import cats.effect.unsafe.implicits.global
import cats.implicits.catsSyntaxApply
import fetch.{FetchService, FileNameService} import fetch.{FetchService, FileNameService}
import fs2.Stream import fs2.Stream
@@ -33,9 +34,11 @@ object Scheduler {
// } // }
def scheduleTask(task: IO[(String, String)]): Stream[IO, (String, String)] = { def scheduleTask(task: IO[(String, String)]): Stream[IO, (String, String)] = {
Stream.eval(durationToNextHalfHour).flatMap { delay => Stream.eval(durationToNextHalfHour).flatMap { delay => {
(Stream.sleep[IO](delay) ++ Stream.awakeEvery[IO](1.hour)).evalMap(_ => task) Stream.eval(IO.println(s"Scheduler started with delay: ${delay.toMinutes} min")) *>
} (Stream.sleep[IO](delay) ++ Stream.awakeEvery[IO](1.hour))
.evalMap(_ => task)
}}
} }
def main(args: Array[String]): Unit = { def main(args: Array[String]): Unit = {