From d625bc6f469b3aeebc232836e91463e19e579f10 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Wed, 28 Feb 2024 14:17:23 +0700 Subject: [PATCH] Use .toResource instead of Resource.eval --- app/src/main/scala/App.scala | 10 +++++----- app/src/main/scala/Executor.scala | 3 +-- app/src/test/scala/CleaningJobTest.scala | 9 ++++----- app/src/test/scala/ExecutorTest.scala | 3 +-- app/src/test/scala/IntegrationTest.scala | 10 ++++------ 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/app/src/main/scala/App.scala b/app/src/main/scala/App.scala index 6ff0c70..a8829d1 100644 --- a/app/src/main/scala/App.scala +++ b/app/src/main/scala/App.scala @@ -14,9 +14,9 @@ object App extends IOApp.Simple: def app: Resource[IO, Unit] = for - config <- Resource.eval(AppConfig.load) - _ <- Resource.eval(Logger[IO].info(s"Starting lila-fishnet with config: $config")) - _ <- Resource.eval(KamonInitiator.apply.init(config.kamon)) + config <- AppConfig.load.toResource + _ <- Logger[IO].info(s"Starting lila-fishnet with config: $config").toResource + _ <- KamonInitiator.apply.init(config.kamon).toResource res <- AppResources.instance(config.redis) _ <- FishnetApp(res, config).run() yield () @@ -26,10 +26,10 @@ class FishnetApp(res: AppResources, config: AppConfig)(using Logger[IO]): for lilaClient <- Resource.pure(LilaClient(res.redisPubsub)) monitor = Monitor.apply - executor <- Resource.eval(Executor.instance(lilaClient, monitor, config.executor)) + executor <- Executor.instance(lilaClient, monitor, config.executor).toResource httpApi = HttpApi(executor, HealthCheck(), config.server) server <- MkHttpServer.apply.newEmber(config.server, httpApi.httpApp) _ <- RedisSubscriberJob(executor, res.redisPubsub).run().background _ <- WorkCleaningJob(executor).run().background - _ <- Resource.eval(Logger[IO].info(s"Starting server on ${config.server.host}:${config.server.port}")) + _ <- Logger[IO].info(s"Starting server on ${config.server.host}:${config.server.port}").toResource yield () diff --git a/app/src/main/scala/Executor.scala b/app/src/main/scala/Executor.scala index 833cf2c..f154b71 100644 --- a/app/src/main/scala/Executor.scala +++ b/app/src/main/scala/Executor.scala @@ -1,7 +1,6 @@ package lila.fishnet -import cats.effect.IO -import cats.effect.kernel.Ref +import cats.effect.{ IO, Ref } import cats.syntax.all.* import java.time.Instant import org.typelevel.log4cats.Logger diff --git a/app/src/test/scala/CleaningJobTest.scala b/app/src/test/scala/CleaningJobTest.scala index 300495c..de28b3c 100644 --- a/app/src/test/scala/CleaningJobTest.scala +++ b/app/src/test/scala/CleaningJobTest.scala @@ -1,7 +1,6 @@ package lila.fishnet -import cats.effect.IO -import cats.effect.kernel.{ Ref, Resource } +import cats.effect.{ IO, Ref } import cats.effect.testkit.TestControl import java.time.Instant import org.typelevel.log4cats.Logger @@ -17,11 +16,11 @@ object CleaningJobTest extends SimpleIOSuite: val times = (60 - 5) / 3 + 1 test(s"cleaning run $times times in 1 minute"): val res = for - ref <- Resource.eval(Ref.of[IO, Int](0)) + ref <- Ref.of[IO, Int](0).toResource executor = createExcutor(ref) _ <- WorkCleaningJob(executor).run().background - _ <- Resource.eval(IO.sleep(1.minute)) - count <- Resource.eval(ref.get) + _ <- IO.sleep(1.minute).toResource + count <- ref.get.toResource yield count TestControl.executeEmbed(res.use(count => IO(expect.same(count, times)))) diff --git a/app/src/test/scala/ExecutorTest.scala b/app/src/test/scala/ExecutorTest.scala index d96eafa..de616cd 100644 --- a/app/src/test/scala/ExecutorTest.scala +++ b/app/src/test/scala/ExecutorTest.scala @@ -1,7 +1,6 @@ package lila.fishnet -import cats.effect.IO -import cats.effect.kernel.Ref +import cats.effect.{ IO, Ref } import cats.syntax.all.* import java.time.Instant import org.typelevel.log4cats.Logger diff --git a/app/src/test/scala/IntegrationTest.scala b/app/src/test/scala/IntegrationTest.scala index 36aa63f..edcdf7f 100644 --- a/app/src/test/scala/IntegrationTest.scala +++ b/app/src/test/scala/IntegrationTest.scala @@ -1,8 +1,6 @@ package lila.fishnet -import cats.effect.IO -import cats.effect.kernel.Ref -import cats.effect.kernel.Resource +import cats.effect.{ IO, Ref, Resource } import cats.syntax.all.* import com.comcast.ip4s.* import com.dimafeng.testcontainers.GenericContainer @@ -88,10 +86,10 @@ object IntegrationTest extends IOSuite: val x = for client <- client - ref <- Resource.eval(Ref.of[IO, List[String]](Nil)) + ref <- Ref.of[IO, List[String]](Nil).toResource _ <- RedisFishnetInListener(res.redisPubsub, ref).background - _ <- Resource.eval(scenario(client)) - x <- Resource.eval(ref.get) + _ <- scenario(client).toResource + x <- ref.get.toResource yield x x.use(x => IO.pure(expect.same(x, expectedMoves)))