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