From 4f343624b7a790a78b31928f07ca8d6117a8c7ed Mon Sep 17 00:00:00 2001 From: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> Date: Wed, 14 Aug 2024 13:35:11 +0530 Subject: [PATCH] revert changes --- .../scala/dev/zio/quickstart/MainApp.scala | 59 ++++++------------- 1 file changed, 18 insertions(+), 41 deletions(-) diff --git a/zio-quickstart-restful-webservice-metrics/src/main/scala/dev/zio/quickstart/MainApp.scala b/zio-quickstart-restful-webservice-metrics/src/main/scala/dev/zio/quickstart/MainApp.scala index 3840b11..25efafa 100644 --- a/zio-quickstart-restful-webservice-metrics/src/main/scala/dev/zio/quickstart/MainApp.scala +++ b/zio-quickstart-restful-webservice-metrics/src/main/scala/dev/zio/quickstart/MainApp.scala @@ -1,3 +1,4 @@ + package dev.zio.quickstart import dev.zio.quickstart.prometheus.PrometheusPublisherApp @@ -5,52 +6,28 @@ import dev.zio.quickstart.users._ import zio._ import zio.http._ import zio.metrics.connectors.{MetricsConfig, prometheus} -import zio.Console._ -import scala.util.Random object MainApp extends ZIOAppDefault { private val metricsConfig = ZLayer.succeed(MetricsConfig(5.seconds)) def run = { - val retries = 5 - val portRangeStart = 8000 - val portRangeEnd = 8005 - - def allocatePort(retriesLeft: Int): ZIO[Any, Throwable, Unit] = - if (retriesLeft <= 0) { - ZIO.fail( - new RuntimeException( - "Failed to allocate a port within the retry limit" - ) - ) - } else { - val randomPort = - Random.nextInt(portRangeEnd - portRangeStart + 1) + portRangeStart - Server - .serve(UserRoutes() ++ PrometheusPublisherApp()) - .provide( - Server.defaultWithPort(randomPort), - - // A layer responsible for storing the state of the `counterApp` - ZLayer.fromZIO(Ref.make(0)), - - // To use the persistence layer, provide the `PersistentUserRepo.layer` layer instead - InmemoryUserRepo.layer, - - // General config for all metric backend - metricsConfig, - - // The Prometheus reporting layer - prometheus.publisherLayer, - prometheus.prometheusLayer - ) - .catchAll(_ => allocatePort(retriesLeft - 1)) - } - - allocatePort(retries) - .fold( - ex => ExitCode.failure, - _ => ExitCode.success + Server + .serve(UserRoutes() ++ PrometheusPublisherApp()) + .provide( + Server.defaultWithPort(8080), + + // An layer responsible for storing the state of the `counterApp` + ZLayer.fromZIO(Ref.make(0)), + + // To use the persistence layer, provide the `PersistentUserRepo.layer` layer instead + InmemoryUserRepo.layer, + + // general config for all metric backend + metricsConfig, + + // The prometheus reporting layer + prometheus.publisherLayer, + prometheus.prometheusLayer ) } }