Restart program 5sec after fatal error

This commit is contained in:
Guntis Smaukstelis
2025-03-03 22:22:20 +02:00
parent 5b99d12d9e
commit b43764b868
+9 -1
View File
@@ -6,10 +6,11 @@ import fetch.csv.{FetchService, FileNameService}
import fetch.dmi import fetch.dmi
import scheduler.Scheduler import scheduler.Scheduler
import server.Server import server.Server
import scala.concurrent.duration.DurationInt
object Main extends IOApp { object Main extends IOApp {
def run(args: List[String]): IO[ExitCode] = { def run(args: List[String]): IO[ExitCode] = {
for { val program = for {
transactor <- DBConnection.transactor[IO] transactor <- DBConnection.transactor[IO]
postgresService <- PostgresService.of(transactor) postgresService <- PostgresService.of(transactor)
_ <- postgresService.createWeatherTable // create table if it does not exists _ <- postgresService.createWeatherTable // create table if it does not exists
@@ -36,5 +37,12 @@ object Main extends IOApp {
exitCode <- (serverTask, fetchCsvTask, cleanupTask, fetchGribTask).parMapN((_, _, _, _) => ExitCode.Success) exitCode <- (serverTask, fetchCsvTask, cleanupTask, fetchGribTask).parMapN((_, _, _, _) => ExitCode.Success)
} yield exitCode } yield exitCode
program.handleErrorWith { error =>
IO.delay {
println(s"Fatal error occurred: ${error.getMessage}")
error.printStackTrace()
} *> IO.sleep(5.seconds) *> run(args)
}
} }
} }