You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.8 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package wow.doge.http4sdemo
  2. import scala.concurrent.duration.MILLISECONDS
  3. import cats.effect.ExitCode
  4. import cats.effect.Resource
  5. import io.odin.Level
  6. import io.odin.consoleLogger
  7. import io.odin.formatter.Formatter
  8. import io.odin.syntax._
  9. import monix.bio.BIOApp
  10. import monix.bio.IO
  11. import monix.bio.Task
  12. import monix.bio.UIO
  13. import slick.jdbc.JdbcProfile
  14. object Main extends BIOApp {
  15. val profile: JdbcProfile = slick.jdbc.PostgresProfile
  16. val app = for {
  17. startTime <- Resource.liftF(IO.clock.realTime(MILLISECONDS))
  18. _ <- Resource.liftF(Task(println("""
  19. | .__ __ __ _____ .___
  20. | | |___/ |__/ |_______ / | | ______ __| _/____ _____ ____
  21. | | | \ __\ __\____ \ / | |_/ ___/ ______ / __ |/ __ \ / \ / _ \
  22. | | Y \ | | | | |_> > ^ /\___ \ /_____/ / /_/ \ ___/| Y Y ( <_> )
  23. | |___| /__| |__| | __/\____ |/____ > \____ |\___ >__|_| /\____/
  24. | \/ |__| |__| \/ \/ \/ \/
  25. """.stripMargin)))
  26. logger <- consoleLogger[Task](
  27. formatter = Formatter.colorful,
  28. minLevel = Level.Debug
  29. ).withAsync()
  30. _ <- Resource.liftF(
  31. logger.info(s"Starting ${BuildInfo.name}-${BuildInfo.version}")
  32. )
  33. db <- SlickResource("myapp.database")
  34. _ <- Resource.liftF(for {
  35. config <- JdbcDatabaseConfig.loadFromGlobal("myapp.database")
  36. _ <- DBMigrations.migrate(config)
  37. } yield ())
  38. _ <- Resource.liftF(
  39. Task.deferAction(implicit s =>
  40. new Server(db, profile, logger).stream.compile.drain
  41. )
  42. )
  43. } yield ()
  44. def run(args: List[String]) = {
  45. app
  46. .use(_ => Task.never)
  47. .onErrorHandleWith(ex => UIO(ex.printStackTrace()))
  48. .as(ExitCode.Success)
  49. }
  50. }