Skip to content

Commit

Permalink
stop the fishnet redis client
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Dec 16, 2019
1 parent 8a8bd84 commit 468056d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions modules/fishnet/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ final class Env(
analysisRepo: lila.analyse.AnalysisRepo,
db: lila.db.Db,
asyncCache: lila.memo.AsyncCache.Builder,
sink: lila.analyse.Analyser
sink: lila.analyse.Analyser,
lifecycle: play.api.inject.ApplicationLifecycle
)(implicit ec: scala.concurrent.ExecutionContext, system: ActorSystem) {

private val config = appConfig.get[FishnetConfig]("fishnet")(AutoConfig.loader)
Expand All @@ -42,7 +43,8 @@ final class Env(
private lazy val redis = new FishnetRedis(
RedisClient create RedisURI.create(config.redisUri),
"fishnet-in",
"fishnet-out"
"fishnet-out",
lifecycle
)

private lazy val clientVersion = new Client.ClientVersion(config.clientMinVersion)
Expand Down
14 changes: 12 additions & 2 deletions modules/fishnet/src/main/FishnetRedis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lila.fishnet
import chess.format.Uci
import io.lettuce.core._
import io.lettuce.core.pubsub._
import scala.concurrent.Future

import lila.hub.actorApi.map.Tell
import lila.hub.actorApi.round.{ FishnetPlay, FishnetStart }
Expand All @@ -11,8 +12,9 @@ import lila.common.Bus
final class FishnetRedis(
client: RedisClient,
chanIn: String,
chanOut: String
) {
chanOut: String,
lifecycle: play.api.inject.ApplicationLifecycle
)(implicit ec: scala.concurrent.ExecutionContext) {

val connIn = client.connectPubSub()
val connOut = client.connectPubSub()
Expand All @@ -35,6 +37,14 @@ final class FishnetRedis(
}
})

lifecycle.addStopHook { () =>
logger.info("Stopping the Redis pool...")
Future {
client.shutdown()
logger.info("Stopped the Redis pool.")
}
}

private def writeWork(work: Work.Move): String =
List(
work.game.id,
Expand Down

0 comments on commit 468056d

Please sign in to comment.