Skip to content

Commit

Permalink
Merge pull request #369 from lichess-org/remove-state-repository
Browse files Browse the repository at this point in the history
Remove state repository
  • Loading branch information
lenguyenthanh authored Nov 26, 2024
2 parents b1bddcb + fb8df44 commit 90e66a6
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 117 deletions.
3 changes: 1 addition & 2 deletions app/src/main/scala/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ class FishnetApp(res: AppResources, config: AppConfig)(using Logger[IO]):

private def createExecutor: Resource[IO, Executor] =
val lilaClient = LilaClient(res.redisPubsub)
val repository = StateRepository.instance(config.repository.path)
Monitor().toResource.flatMap(Executor.instance(lilaClient, repository, _, config.executor))
Monitor().toResource.flatMap(Executor.instance(lilaClient, _, config.executor))
11 changes: 2 additions & 9 deletions app/src/main/scala/AppConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ object AppConfig:
RedisConfig.config,
HttpServerConfig.config,
KamonConfig.config,
ExecutorConfg.config,
RepositoryConfig.config
ExecutorConfg.config
).parMapN(AppConfig.apply)

case class AppConfig(
redis: RedisConfig,
server: HttpServerConfig,
kamon: KamonConfig,
executor: ExecutorConfig,
repository: RepositoryConfig
executor: ExecutorConfig
)

case class HttpServerConfig(host: Host, port: Port, apiLogger: Boolean, shutdownTimeout: Int)
Expand Down Expand Up @@ -52,8 +50,3 @@ case class ExecutorConfig(maxSize: Int)
object ExecutorConfg:
def maxSize = env("APP_MAX_MOVE_SIZE").or(prop("app.max.move.size")).as[Int].default(300)
def config = maxSize.map(ExecutorConfig.apply)

case class RepositoryConfig(path: Option[String])
object RepositoryConfig:
def path = env("APP_BACKUP_FILE").or(prop("app.backup.file")).as[String].option
def config = path.map(RepositoryConfig.apply)
9 changes: 3 additions & 6 deletions app/src/main/scala/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@ object Executor:

import AppState.*

def instance(client: LilaClient, repository: StateRepository, monitor: Monitor, config: ExecutorConfig)(
using Logger[IO]
def instance(client: LilaClient, monitor: Monitor, config: ExecutorConfig)(using
Logger[IO]
): Resource[IO, Executor] =
Ref
.of[IO, AppState](AppState.empty)
.toResource
.flatMap: ref =>
Resource
.make(repository.get.flatMap(ref.set))(_ => ref.get.flatMap(repository.save))
.as(instance(ref, client, monitor, config))
.map(instance(_, client, monitor, config))

def instance(ref: Ref[IO, AppState], client: LilaClient, monitor: Monitor, config: ExecutorConfig)(using
Logger[IO]
Expand Down
61 changes: 0 additions & 61 deletions app/src/main/scala/StateRepository.scala

This file was deleted.

14 changes: 7 additions & 7 deletions app/src/main/scala/http/ApiLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ import org.typelevel.log4cats.Logger

object ApiLogger:

private def isResponseError(res: Response[IO]): Boolean =
!res.status.isSuccess && res.status.code != 404

private def logError(req: Request[IO], res: Response[IO])(using Logger[IO]): IO[Unit] =
Http4sLogger.logMessage(req)(true, true)(Logger[IO].warn) >>
Http4sLogger.logMessage(res)(true, true)(Logger[IO].warn)

def apply(isVerbose: Boolean)(using Logger[IO]): HttpRoutes[IO] => HttpRoutes[IO] =
if isVerbose then verboseLogger
else errorLogger
Expand All @@ -30,3 +23,10 @@ object ApiLogger:
private def verboseLogger =
RequestLogger.httpRoutes[IO](true, true) andThen
ResponseLogger.httpRoutes[IO, Request[IO]](true, true)

private def isResponseError(res: Response[IO]): Boolean =
!res.status.isSuccess && res.status.code != 404

private def logError(req: Request[IO], res: Response[IO])(using Logger[IO]): IO[Unit] =
Http4sLogger.logMessage(req)(true, true)(Logger[IO].warn) >>
Http4sLogger.logMessage(res)(true, true)(Logger[IO].warn)
4 changes: 0 additions & 4 deletions app/src/test/scala/Helper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ object Helper:

val noopLilaClient: LilaClient = new:
def send(move: Lila.Response): IO[Unit] = IO.unit

val noopStateRepository: StateRepository = new:
def get: IO[AppState] = IO.pure(AppState.empty)
def save(state: AppState): IO[Unit] = IO.unit
3 changes: 1 addition & 2 deletions app/src/test/scala/IntegrationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ object IntegrationTest extends IOSuite:
server = HttpServerConfig(ip"0.0.0.0", port"9999", apiLogger = false, shutdownTimeout = 30),
redis = redis,
kamon = KamonConfig(enabled = false),
executor = ExecutorConfig(maxSize = 300),
repository = RepositoryConfig(path = None)
executor = ExecutorConfig(maxSize = 300)
)

test("health check should return healthy"):
Expand Down
17 changes: 0 additions & 17 deletions app/src/test/scala/TaskCodecTest.scala

This file was deleted.

4 changes: 0 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ lazy val app = project
circeCore,
cirisCore,
cirisHtt4s,
fs2,
fs2IO,
fs2Json,
fs2JsonCirce,
http4sCirce,
http4sDsl,
http4sServer,
Expand Down
5 changes: 0 additions & 5 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ object Dependencies {
val catsCore = "org.typelevel" %% "cats-core" % "2.12.0"
val catsEffect = "org.typelevel" %% "cats-effect" % V.catsEffect

val fs2 = "co.fs2" %% "fs2-core" % "3.11.0"
val fs2IO = "co.fs2" %% "fs2-io" % "3.11.0"
val fs2Json = "org.gnieh" %% "fs2-data-json" % "1.11.1"
val fs2JsonCirce = "org.gnieh" %% "fs2-data-json-circe" % "1.11.1"

val circeCore = circe("core")
val circeLiteral = circe("literal") % Test

Expand Down

0 comments on commit 90e66a6

Please sign in to comment.