Files
WeatherTool/src/main/scala/app/Main.scala
T

37 lines
1.0 KiB
Scala
Raw Normal View History

package app
import cats.effect._
2023-05-17 01:20:01 +03:00
import cats.implicits.catsSyntaxTuple2Parallel
import db.Main.transactor
import db.{DataService, FileService, PostgresService}
import doobie.Transactor
import fetch.{FetchService, FileFetchScheduler}
import server.Server
object Main extends IOApp {
def transactor[F[_] : Async]: Transactor[F] = Transactor.fromDriverManager[F](
"org.postgresql.Driver",
"jdbc:postgresql://localhost:5432/weather-tool",
"postgres",
"mysecretpassword"
)
def run(args: List[String]): IO[ExitCode] = {
val xa = transactor[IO]
for {
postgresService <- PostgresService.of(xa)
2023-10-22 23:51:59 +03:00
fileService <- FileService.of
dataService <- DataService.of(fileService, postgresService)
2023-06-22 13:59:44 +03:00
fetch <- FetchService.of
fileFetchScheduler <- FileFetchScheduler.of(dataService, fetch)
schedulerTask = fileFetchScheduler.run.compile.drain
2023-06-22 13:59:44 +03:00
server <- Server.of(dataService, fetch)
serverTask = server.run
2023-06-22 13:59:44 +03:00
exitCode <- (serverTask, schedulerTask).parMapN((_, _) => ExitCode.Success)
} yield exitCode
}
}