generated from softwaremill/sbt-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fastAi.scala
41 lines (32 loc) · 1.16 KB
/
fastAi.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
package scalar
import org.slf4j.LoggerFactory
import ox.{supervised, useInScope}
import scalar.infrastructure.{SetupNettyHttpServer, SetupOtel, SetupRedissonClient}
import sttp.client4.DefaultSyncBackend
import sttp.tapir.*
import sttp.tapir.server.ServerEndpoint
import sttp.tapir.server.netty.loom.Id
import scala.io.StdIn
@main def fastAi(): Unit =
val logger = LoggerFactory.getLogger(this.getClass)
supervised {
val scalarConfig = ScalarConfig.load()
val otel = SetupOtel().setup()
val redissonClient = useInScope(SetupRedissonClient.setup())(_.shutdown())
val backend = useInScope(DefaultSyncBackend())(_.close())
val updateCacheTasks = runUpdateCache(redissonClient)
val apiEndpoints: List[ServerEndpoint[Any, Id]] = List(
fastAiServerEndpoint(
redissonClient,
backend,
updateCacheTasks,
scalarConfig,
otel
)
)
val nettyBinding = useInScope(SetupNettyHttpServer.start(otel, apiEndpoints))(_.stop())
logger.info(s"Go to http://localhost:${nettyBinding.port}/docs to open SwaggerUI.")
logger.info("Press ENTER key to exit.")
val _ = StdIn.readLine()
logger.info("Bye!")
}