Skip to content

Commit

Permalink
Remove unnecessary actor system termination in example apps
Browse files Browse the repository at this point in the history
It's already handled by AkkaCluster/PekkoCluster managed resources
  • Loading branch information
Jonas Chapuis committed Feb 7, 2024
1 parent aa1ba0f commit 4af1ebf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 41 deletions.
33 changes: 13 additions & 20 deletions example/src/main/scala/endless/example/app/akka/AkkaApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
33 changes: 13 additions & 20 deletions example/src/main/scala/endless/example/app/pekko/PekkoApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit 4af1ebf

Please sign in to comment.