Skip to content

Commit

Permalink
move the forkDaemon into the for comprehension
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone committed Oct 23, 2023
1 parent 8418f1f commit b79d281
Showing 1 changed file with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,33 @@ object InstrumentationServer {

private val instrumentationServer =
for {
index <- ZIO.service[IndexApp].map(_.route)
health <- ZIO.service[HealthRouteZ].map(_.route)
prometheus <- ZIO.service[PrometheusApp].map(_.route)
index <- ZIO.serviceWith[IndexApp](_.route)
health <- ZIO.serviceWith[HealthRouteZ](_.route)
prometheus <- ZIO.serviceWith[PrometheusApp](_.route)
app = index ++ health ++ prometheus
_ <- Server.serve(app)
_ <- Server.serve(app).forkDaemon
} yield ()

val make: ZIO[State with AppConfig, Throwable, Fiber.Runtime[Throwable, Unit]] =
ZIO
.service[AppConfig]
.flatMap { config =>
val port = config.instrumentationServerConfig.port
val interval = config.instrumentationServerConfig.interval
val metricsConfig = MetricsConfig(interval)
ZIO.logInfo(s"Starting instrumentation http server on port: $port") *>
instrumentationServer
.provideSome[State](
// HTTP Server
Server.defaultWithPort(port),
// HTTP routes
IndexApp.layer,
HealthRouteZ.layer,
PrometheusApp.layer,
// Metrics dependencies
prometheus.publisherLayer,
ZLayer.succeed(metricsConfig) >>> prometheus.prometheusLayer,
Runtime.enableRuntimeMetrics,
Runtime.enableFiberRoots,
DefaultJvmMetrics.live.unit
)
.forkDaemon
}
val make: ZIO[State with AppConfig, Throwable, Unit] =
ZIO.serviceWithZIO[AppConfig] { config =>
val port = config.instrumentationServerConfig.port
val interval = config.instrumentationServerConfig.interval
val metricsConfig = MetricsConfig(interval)
ZIO.logInfo(s"Starting instrumentation http server on port: $port") *>
instrumentationServer
.provideSome[State](
// HTTP Server
Server.defaultWithPort(port),
// HTTP routes
IndexApp.layer,
HealthRouteZ.layer,
PrometheusApp.layer,
// Metrics dependencies
prometheus.publisherLayer,
ZLayer.succeed(metricsConfig) >>> prometheus.prometheusLayer,
Runtime.enableRuntimeMetrics,
Runtime.enableFiberRoots,
DefaultJvmMetrics.live.unit
)
}
}

0 comments on commit b79d281

Please sign in to comment.