Moved to app/Main, scheduler helper methods moved to unfinished test
This commit is contained in:
@@ -5,7 +5,7 @@ ThisBuild / scalaVersion := "2.13.10"
|
|||||||
lazy val root = (project in file("."))
|
lazy val root = (project in file("."))
|
||||||
.settings(
|
.settings(
|
||||||
name := "WeatherTool",
|
name := "WeatherTool",
|
||||||
Compile / mainClass := Some("server.Main")
|
Compile / mainClass := Some("app.Main")
|
||||||
)
|
)
|
||||||
|
|
||||||
val http4sVersion = "0.23.18"
|
val http4sVersion = "0.23.18"
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package server
|
package app
|
||||||
|
|
||||||
import cats.effect._
|
import cats.effect._
|
||||||
import cats.implicits.catsSyntaxTuple2Parallel
|
import cats.implicits.catsSyntaxTuple2Parallel
|
||||||
import db.{DBService, DataService}
|
import db.{DBService, DataService}
|
||||||
import fetch.{FetchService, FileFetchScheduler}
|
import fetch.{FetchService, FileFetchScheduler}
|
||||||
|
import server.Server
|
||||||
|
|
||||||
object Main extends IOApp {
|
object Main extends IOApp {
|
||||||
def run(args: List[String]): IO[ExitCode] = {
|
def run(args: List[String]): IO[ExitCode] = {
|
||||||
@@ -12,7 +12,6 @@ import pureconfig._
|
|||||||
import pureconfig.generic.auto._
|
import pureconfig.generic.auto._
|
||||||
|
|
||||||
import java.time.{LocalDate, LocalDateTime}
|
import java.time.{LocalDate, LocalDateTime}
|
||||||
import scala.concurrent.ExecutionContext.global
|
|
||||||
|
|
||||||
final case class WeatherServerConfig(
|
final case class WeatherServerConfig(
|
||||||
username: String,
|
username: String,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package fetch
|
package fetch
|
||||||
|
|
||||||
import cats.effect._
|
import cats.effect._
|
||||||
import cats.effect.unsafe.implicits.global
|
|
||||||
import cats.implicits.catsSyntaxApply
|
import cats.implicits.catsSyntaxApply
|
||||||
import fs2.Stream
|
import fs2.Stream
|
||||||
import org.typelevel.log4cats.Logger
|
import org.typelevel.log4cats.Logger
|
||||||
@@ -22,10 +21,6 @@ object Scheduler {
|
|||||||
class Scheduler(log: Logger[IO]) {
|
class Scheduler(log: Logger[IO]) {
|
||||||
private val downloadMinute = 31
|
private val downloadMinute = 31
|
||||||
|
|
||||||
// private def testTask: IO[Unit] = {
|
|
||||||
// log.info("Running task")
|
|
||||||
// }
|
|
||||||
|
|
||||||
def durationToNextHalfHour(implicit clock: Clock[IO]): IO[FiniteDuration] = {
|
def durationToNextHalfHour(implicit clock: Clock[IO]): IO[FiniteDuration] = {
|
||||||
clock.realTime.map { duration =>
|
clock.realTime.map { duration =>
|
||||||
val now = LocalTime.ofSecondOfDay((duration.toMillis / 1000) % (24 * 60 * 60))
|
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)]] = {
|
def scheduleTask(task: IO[Either[Throwable, (String, String)]]): Stream[IO, Either[Throwable, (String, String)]] = {
|
||||||
Stream.eval(durationToNextHalfHour).flatMap { delay => {
|
Stream.eval(durationToNextHalfHour).flatMap { delay => {
|
||||||
Stream.eval(log.info(s"Scheduler started with delay: ${delay.toMinutes} min")) *>
|
Stream.eval(log.info(s"Scheduler started with delay: ${delay.toMinutes} min")) *>
|
||||||
@@ -50,13 +39,4 @@ class Scheduler(log: Logger[IO]) {
|
|||||||
.evalMap(_ => task)
|
.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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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()
|
||||||
|
// }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user