From 4af1ebf65b867186184a93db70df03e4dc78fc0e Mon Sep 17 00:00:00 2001 From: Jonas Chapuis Date: Wed, 7 Feb 2024 10:42:56 +0100 Subject: [PATCH] Remove unnecessary actor system termination in example apps It's already handled by AkkaCluster/PekkoCluster managed resources --- .../endless/example/app/akka/AkkaApp.scala | 33 ++++++++----------- .../endless/example/app/pekko/PekkoApp.scala | 33 ++++++++----------- .../runtime/pekko/deploy/PekkoCluster.scala | 2 +- 3 files changed, 27 insertions(+), 41 deletions(-) diff --git a/example/src/main/scala/endless/example/app/akka/AkkaApp.scala b/example/src/main/scala/endless/example/app/akka/AkkaApp.scala index 62c30ea4..c990a11f 100644 --- a/example/src/main/scala/endless/example/app/akka/AkkaApp.scala +++ b/example/src/main/scala/endless/example/app/akka/AkkaApp.scala @@ -40,28 +40,21 @@ object AkkaApp extends Bookings with Vehicles with Availabilities { .flatMap(createAkkaApp(port)) private def actorSystem(executionContext: ExecutionContext): Resource[IO, ActorSystem[Nothing]] = - Resource.make( - IO( - ActorSystem.wrap( - akka.actor.ActorSystem( - name = "example-akka-as", - config = Some( - PersistenceTestKitPlugin.config - .withFallback(PersistenceTestKitDurableStateStorePlugin.config) - .withFallback(ConfigFactory.defaultApplication) - .resolve() - ), - defaultExecutionContext = Some(executionContext), - classLoader = None - ) + IO( + ActorSystem.wrap( + akka.actor.ActorSystem( + name = "example-akka-as", + config = Some( + PersistenceTestKitPlugin.config + .withFallback(PersistenceTestKitDurableStateStorePlugin.config) + .withFallback(ConfigFactory.defaultApplication) + .resolve() + ), + defaultExecutionContext = Some(executionContext), + classLoader = None ) ) - )(system => - IO.fromFuture(IO.blocking { - system.terminate() - system.whenTerminated - }).void - ) + ).toResource // #main private def createAkkaApp(port: Int)(actorSystem: ActorSystem[Nothing]): Resource[IO, Server] = { diff --git a/example/src/main/scala/endless/example/app/pekko/PekkoApp.scala b/example/src/main/scala/endless/example/app/pekko/PekkoApp.scala index ca667c9e..fbd342af 100644 --- a/example/src/main/scala/endless/example/app/pekko/PekkoApp.scala +++ b/example/src/main/scala/endless/example/app/pekko/PekkoApp.scala @@ -39,28 +39,21 @@ object PekkoApp extends Bookings with Vehicles with Availabilities { .flatMap(createPekkoApp(port)) private def actorSystem(executionContext: ExecutionContext): Resource[IO, ActorSystem[Nothing]] = - Resource.make( - IO( - ActorSystem.wrap( - org.apache.pekko.actor.ActorSystem( - name = "example-pekko-as", - config = Some( - PersistenceTestKitPlugin.config - .withFallback(PersistenceTestKitDurableStateStorePlugin.config) - .withFallback(ConfigFactory.defaultApplication) - .resolve() - ), - defaultExecutionContext = Some(executionContext), - classLoader = None - ) + IO( + ActorSystem.wrap( + org.apache.pekko.actor.ActorSystem( + name = "example-pekko-as", + config = Some( + PersistenceTestKitPlugin.config + .withFallback(PersistenceTestKitDurableStateStorePlugin.config) + .withFallback(ConfigFactory.defaultApplication) + .resolve() + ), + defaultExecutionContext = Some(executionContext), + classLoader = None ) ) - )(system => - IO.fromFuture(IO.blocking { - system.terminate() - system.whenTerminated - }).void - ) + ).toResource private def createPekkoApp(port: Int)(actorSystem: ActorSystem[Nothing]): Resource[IO, Server] = { implicit val askTimeout: Timeout = Timeout(10.seconds) diff --git a/pekko-runtime/src/main/scala/endless/runtime/pekko/deploy/PekkoCluster.scala b/pekko-runtime/src/main/scala/endless/runtime/pekko/deploy/PekkoCluster.scala index 03b04aad..8dd766f5 100644 --- a/pekko-runtime/src/main/scala/endless/runtime/pekko/deploy/PekkoCluster.scala +++ b/pekko-runtime/src/main/scala/endless/runtime/pekko/deploy/PekkoCluster.scala @@ -104,7 +104,7 @@ object PekkoCluster { "Timed out during cluster shutdown while waiting for actor system to terminate" ) ) - _ <- Logger[F].info("pekko cluster exited and actor system shutdown complete") + _ <- Logger[F].info("Pekko cluster exited and actor system shutdown complete") } yield () (cluster, release) })