Moved to app/Main, scheduler helper methods moved to unfinished test

This commit is contained in:
Guntis Smaukstelis
2023-05-25 13:51:45 +03:00
parent d651e3f3bd
commit 1abb12d92a
5 changed files with 30 additions and 24 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ ThisBuild / scalaVersion := "2.13.10"
lazy val root = (project in file("."))
.settings(
name := "WeatherTool",
Compile / mainClass := Some("server.Main")
Compile / mainClass := Some("app.Main")
)
val http4sVersion = "0.23.18"
@@ -1,8 +1,10 @@
package server
package app
import cats.effect._
import cats.implicits.catsSyntaxTuple2Parallel
import db.{DBService, DataService}
import fetch.{FetchService, FileFetchScheduler}
import server.Server
object Main extends IOApp {
def run(args: List[String]): IO[ExitCode] = {
-1
View File
@@ -12,7 +12,6 @@ import pureconfig._
import pureconfig.generic.auto._
import java.time.{LocalDate, LocalDateTime}
import scala.concurrent.ExecutionContext.global
final case class WeatherServerConfig(
username: String,
+1 -21
View File
@@ -1,7 +1,6 @@
package fetch
import cats.effect._
import cats.effect.unsafe.implicits.global
import cats.implicits.catsSyntaxApply
import fs2.Stream
import org.typelevel.log4cats.Logger
@@ -22,10 +21,6 @@ object Scheduler {
class Scheduler(log: Logger[IO]) {
private val downloadMinute = 31
// private def testTask: IO[Unit] = {
// log.info("Running task")
// }
def durationToNextHalfHour(implicit clock: Clock[IO]): IO[FiniteDuration] = {
clock.realTime.map { duration =>
val now = LocalTime.ofSecondOfDay((duration.toMillis / 1000) % (24 * 60 * 60))
@@ -37,12 +32,6 @@ class Scheduler(log: Logger[IO]) {
}
}
// def run(implicit clock: Clock[IO]): Stream[IO, Nothing] = {
// Stream.eval(durationToNextHalfHour).flatMap { delay =>
// (Stream.sleep[IO](delay) ++ Stream.awakeEvery[IO](1.hour)).evalMap(_ => testTask).drain
// }
// }
def scheduleTask(task: IO[Either[Throwable, (String, String)]]): Stream[IO, Either[Throwable, (String, String)]] = {
Stream.eval(durationToNextHalfHour).flatMap { delay => {
Stream.eval(log.info(s"Scheduler started with delay: ${delay.toMinutes} min")) *>
@@ -50,13 +39,4 @@ class Scheduler(log: Logger[IO]) {
.evalMap(_ => task)
}}
}
// This is just for testing
def main(args: Array[String]): Unit = {
// run.compile.drain.unsafeRunSync()
for {
fetch <- FetchService.of
fetchTask = new FileNameService().generateCurrentHour.flatMap(fetch.fetchSingleFile)
} yield scheduleTask(fetchTask).compile.drain.unsafeRunSync()
}
}
}
+25
View File
@@ -0,0 +1,25 @@
package fetch
import cats.effect.{Clock, IO}
import fs2.Stream
class SchedulerSpec {
// private def testTask: IO[Unit] = {
// log.info("Running task")
// }
//
// def run(implicit clock: Clock[IO]): Stream[IO, Nothing] = {
// Stream.eval(durationToNextHalfHour).flatMap { delay =>
// (Stream.sleep[IO](delay) ++ Stream.awakeEvery[IO](1.hour)).evalMap(_ => testTask).drain
// }
// }
//
// def main(args: Array[String]): Unit = {
// // run.compile.drain.unsafeRunSync()
// for {
// scheduler <- Scheduler.of
// fetch <- FetchService.of
// fetchTask = new FileNameService().generateCurrentHour.flatMap(fetch.fetchSingleFile)
// } yield scheduler.scheduleTask(fetchTask).compile.drain.unsafeRunSync()
// }
}