diff --git a/webapi/src/main/scala/org/knora/webapi/core/ActorSystem.scala b/webapi/src/main/scala/org/knora/webapi/core/ActorSystem.scala index e1a527bb3b..f114648ff5 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/ActorSystem.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/ActorSystem.scala @@ -32,13 +32,13 @@ object ActorSystem { defaultExecutionContext = Some(executionContext) ) ) - .tap(_ => ZIO.logInfo(">>> Acquire Actor System <<<")) + .zipLeft(ZIO.logInfo(">>> Acquire Actor System <<<")) .orDie private def release(system: akka.actor.ActorSystem): URIO[Any, actor.Terminated] = ZIO .fromFuture(_ => system.terminate()) - .tap(_ => ZIO.logInfo(">>> Release Actor System <<<")) + .zipLeft(ZIO.logInfo(">>> Release Actor System <<<")) .orDie val layer: ZLayer[AppConfig, Nothing, ActorSystem] = @@ -46,7 +46,7 @@ object ActorSystem { for { config <- ZIO.service[AppConfig] context <- ZIO.executor.map(_.asExecutionContext) - actorSystem <- ZIO.acquireRelease(acquire(context))(release _) + actorSystem <- ZIO.acquireRelease(acquire(context))(release) } yield new ActorSystem { override val system: akka.actor.ActorSystem = actorSystem override val cacheServiceSettings: CacheServiceSettings = new CacheServiceSettings(config) diff --git a/webapi/src/main/scala/org/knora/webapi/core/AppServer.scala b/webapi/src/main/scala/org/knora/webapi/core/AppServer.scala index ac805f966c..a4151a4a2f 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/AppServer.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/AppServer.scala @@ -58,8 +58,7 @@ final case class AppServer( private def upgradeRepository(requiresRepository: Boolean): ZIO[Any, Nothing, Unit] = for { _ <- state.set(AppState.UpdatingRepository) - _ <- if (requiresRepository) ru.maybeUpgradeRepository.flatMap(response => ZIO.logInfo(response.message)) - else ZIO.unit + _ <- ru.maybeUpgradeRepository.flatMap(response => ZIO.logInfo(response.message)).when(requiresRepository) _ <- state.set(AppState.RepositoryUpToDate) } yield () @@ -84,8 +83,7 @@ final case class AppServer( private def populateOntologyCaches(requiresRepository: Boolean): ZIO[Any, Nothing, Unit] = for { _ <- state.set(AppState.LoadingOntologies) - _ <- if (requiresRepository) ar.populateOntologyCaches - else ZIO.unit + _ <- ar.populateOntologyCaches.when(requiresRepository) _ <- state.set(AppState.OntologiesReady) } yield () @@ -97,19 +95,15 @@ final case class AppServer( private def checkIIIFService(requiresIIIFService: Boolean): ZIO[Any, Nothing, Unit] = for { _ <- state.set(AppState.WaitingForIIIFService) - _ <- if (requiresIIIFService) - iiifs - .getStatus() - .flatMap(status => - status match { - case IIIFServiceStatusOK => - ZIO.logInfo("IIIF service running") - case IIIFServiceStatusNOK => - ZIO.logError("IIIF service not running") *> ZIO.die(new Exception("IIIF service not running")) - } - ) - else - ZIO.unit + _ <- iiifs + .getStatus() + .flatMap { + case IIIFServiceStatusOK => + ZIO.logInfo("IIIF service running") + case IIIFServiceStatusNOK => + ZIO.logError("IIIF service not running") *> ZIO.die(new Exception("IIIF service not running")) + } + .when(requiresIIIFService) _ <- state.set(AppState.IIIFServiceReady) } yield () @@ -119,15 +113,12 @@ final case class AppServer( private val checkCacheService: ZIO[Any, Nothing, Unit] = for { _ <- state.set(AppState.WaitingForCacheService) - _ <- cs.getStatus - .flatMap(status => - status match { - case CacheServiceStatusNOK => - ZIO.logError("Cache service not running.") *> ZIO.die(new Exception("Cache service not running.")) - case CacheServiceStatusOK => - ZIO.unit - } - ) + _ <- cs.getStatus.flatMap { + case CacheServiceStatusNOK => + ZIO.logError("Cache service not running.") *> ZIO.die(new Exception("Cache service not running.")) + case CacheServiceStatusOK => + ZIO.unit + } _ <- state.set(AppState.CacheServiceReady) } yield () @@ -141,7 +132,7 @@ final case class AppServer( def start( requiresAdditionalRepositoryChecks: Boolean, requiresIIIFService: Boolean - ) = + ): ZIO[Any, Nothing, Unit] = for { _ <- ZIO.logInfo("=> Startup checks initiated") _ <- checkTriplestoreService @@ -152,7 +143,7 @@ final case class AppServer( _ <- checkCacheService _ <- ZIO.logInfo("=> Startup checks finished") _ <- ZIO.logInfo(s"DSP-API Server started: ${appConfig.knoraApi.internalKnoraApiBaseUrl}") - _ <- if (appConfig.allowReloadOverHttp) ZIO.logWarning("Resetting DB over HTTP is turned ON") else ZIO.unit + _ <- ZIO.logWarning("Resetting DB over HTTP is turned ON").when(appConfig.allowReloadOverHttp) _ <- state.set(AppState.Running) } yield () } diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServer.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServer.scala index 9d3a427279..811383f14a 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServer.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServer.scala @@ -34,7 +34,7 @@ object HttpServer { .fromFuture(_ => Http().newServerAt(config.knoraApi.internalHost, config.knoraApi.internalPort).bind(apiRoutes.routes) ) - .tap(_ => ZIO.logInfo(">>> Acquire HTTP Server <<<")) + .zipLeft(ZIO.logInfo(">>> Acquire HTTP Server <<<")) .orDie } { serverBinding => ZIO @@ -43,7 +43,7 @@ object HttpServer { new scala.concurrent.duration.FiniteDuration(1, scala.concurrent.duration.MILLISECONDS) ) ) - .tap(_ => ZIO.logInfo(">>> Release HTTP Server <<<")) + .zipLeft(ZIO.logInfo(">>> Release HTTP Server <<<")) .orDie } } diff --git a/webapi/src/main/scala/org/knora/webapi/core/State.scala b/webapi/src/main/scala/org/knora/webapi/core/State.scala index 9a9c43fb01..dd6f277401 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/State.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/State.scala @@ -13,8 +13,7 @@ import org.knora.webapi.core.domain.AppState @accessible trait State { def set(v: AppState): UIO[Unit] - val get: UIO[AppState] - + def get: UIO[AppState] } object State { diff --git a/webapi/src/main/scala/org/knora/webapi/core/actors/RoutingActor.scala b/webapi/src/main/scala/org/knora/webapi/core/actors/RoutingActor.scala index 75ebd3dc8c..4ab975aa4a 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/actors/RoutingActor.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/actors/RoutingActor.scala @@ -76,7 +76,7 @@ class RoutingActor( ) extends Actor { implicit val system: ActorSystem = context.system - val log: Logger = Logger(this.getClass()) + val log: Logger = Logger(this.getClass) /** * The Cache Service's configuration.