-
Notifications
You must be signed in to change notification settings - Fork 20
/
Main.scala
62 lines (57 loc) · 1.87 KB
/
Main.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package io.pager
import canoe.api.{ TelegramClient => CanoeClient }
import io.pager.client.github.GitHubClient
import io.pager.client.http.HttpClient
import io.pager.client.telegram.TelegramClient
import io.pager.client.telegram.scenario.CanoeScenarios
import io.pager.log.Logger
import io.pager.lookup.ReleaseChecker
import io.pager.subscription.SubscriptionLogic
import io.pager.subscription.chat.ChatStorage
import io.pager.subscription.repository.RepositoryVersionStorage
import io.pager.validation.RepositoryValidator
import org.http4s.blaze.client.BlazeClientBuilder
import org.http4s.client.Client
import zio._
import zio.interop.catz._
object Main extends ZIOAppDefault {
val http4sClient: RLayer[Scope, Client[Task]] = ZLayer {
BlazeClientBuilder
.apply[Task]
.resource
.toScopedZIO
}
val canoeClient: RLayer[Scope with Config, CanoeClient[Task]] = ZLayer {
ZIO.service[Config].flatMap { config =>
CanoeClient[Task](config.releasePager.botToken).toScopedZIO
}
}
override def run: RIO[Scope, Unit] = {
val program =
for {
flywayMigration <- ZIO.service[FlywayMigration]
telegramClient <- ZIO.service[TelegramClient]
releaseChecker <- ZIO.service[ReleaseChecker]
_ <- flywayMigration.migrate
_ <- telegramClient.start &> releaseChecker.scheduleRefresh.repeat(Schedule.spaced(1.minute))
} yield ()
program
.provideSome[Scope](
Config.live,
http4sClient,
HttpClient.http4s,
canoeClient,
Transactor.live,
FlywayMigration.live,
ReleaseChecker.live,
CanoeScenarios.live,
TelegramClient.canoe,
RepositoryValidator.live,
SubscriptionLogic.live,
Logger.console,
GitHubClient.live,
ChatStorage.doobie,
RepositoryVersionStorage.doobie
)
}
}