Skip to content

Commit

Permalink
Use .toResource instead of Resource.eval
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Feb 28, 2024
1 parent 60cdfaf commit d625bc6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
10 changes: 5 additions & 5 deletions app/src/main/scala/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -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 ()
3 changes: 1 addition & 2 deletions app/src/main/scala/Executor.scala
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 4 additions & 5 deletions app/src/test/scala/CleaningJobTest.scala
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))))

Expand Down
3 changes: 1 addition & 2 deletions app/src/test/scala/ExecutorTest.scala
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 4 additions & 6 deletions app/src/test/scala/IntegrationTest.scala
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)))

Expand Down

0 comments on commit d625bc6

Please sign in to comment.