cloud eval live setting
parent
87ef26b856
commit
af4efb40b3
|
@ -27,7 +27,8 @@ final class Dev(env: Env) extends LilaController(env) {
|
||||||
env.noDelaySecretSetting,
|
env.noDelaySecretSetting,
|
||||||
env.featuredTeamsSetting,
|
env.featuredTeamsSetting,
|
||||||
env.prizeTournamentMakers,
|
env.prizeTournamentMakers,
|
||||||
env.pieceImageExternal
|
env.pieceImageExternal,
|
||||||
|
env.evalCache.enable
|
||||||
)
|
)
|
||||||
|
|
||||||
def settings =
|
def settings =
|
||||||
|
|
|
@ -16,6 +16,7 @@ final class Env(
|
||||||
userRepo: lila.user.UserRepo,
|
userRepo: lila.user.UserRepo,
|
||||||
yoloDb: lila.db.AsyncDb @@ lila.db.YoloDb,
|
yoloDb: lila.db.AsyncDb @@ lila.db.YoloDb,
|
||||||
cacheApi: lila.memo.CacheApi,
|
cacheApi: lila.memo.CacheApi,
|
||||||
|
settingStore: lila.memo.SettingStore.Builder,
|
||||||
scheduler: akka.actor.Scheduler
|
scheduler: akka.actor.Scheduler
|
||||||
)(implicit
|
)(implicit
|
||||||
ec: scala.concurrent.ExecutionContext,
|
ec: scala.concurrent.ExecutionContext,
|
||||||
|
@ -27,6 +28,12 @@ final class Env(
|
||||||
|
|
||||||
private lazy val truster = wire[EvalCacheTruster]
|
private lazy val truster = wire[EvalCacheTruster]
|
||||||
|
|
||||||
|
lazy val enable = settingStore[Boolean](
|
||||||
|
"useCeval",
|
||||||
|
default = true,
|
||||||
|
text = "Enable cloud eval (disable in case of server trouble)".some
|
||||||
|
)
|
||||||
|
|
||||||
private lazy val upgrade = wire[EvalCacheUpgrade]
|
private lazy val upgrade = wire[EvalCacheUpgrade]
|
||||||
|
|
||||||
lazy val api: EvalCacheApi = wire[EvalCacheApi]
|
lazy val api: EvalCacheApi = wire[EvalCacheApi]
|
||||||
|
|
|
@ -9,12 +9,13 @@ import lila.socket.Socket
|
||||||
import lila.memo.ExpireCallbackMemo
|
import lila.memo.ExpireCallbackMemo
|
||||||
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
|
import lila.memo.SettingStore
|
||||||
|
|
||||||
/* Upgrades the user's eval when a better one becomes available,
|
/* Upgrades the user's eval when a better one becomes available,
|
||||||
* by remembering the last evalGet of each socket member,
|
* by remembering the last evalGet of each socket member,
|
||||||
* and listening to new evals stored.
|
* and listening to new evals stored.
|
||||||
*/
|
*/
|
||||||
final private class EvalCacheUpgrade(scheduler: akka.actor.Scheduler)(implicit
|
final private class EvalCacheUpgrade(setting: SettingStore[Boolean], scheduler: akka.actor.Scheduler)(implicit
|
||||||
ec: scala.concurrent.ExecutionContext,
|
ec: scala.concurrent.ExecutionContext,
|
||||||
mode: play.api.Mode
|
mode: play.api.Mode
|
||||||
) {
|
) {
|
||||||
|
@ -26,17 +27,18 @@ final private class EvalCacheUpgrade(scheduler: akka.actor.Scheduler)(implicit
|
||||||
|
|
||||||
private val upgradeMon = lila.mon.evalCache.upgrade
|
private val upgradeMon = lila.mon.evalCache.upgrade
|
||||||
|
|
||||||
def register(sri: Socket.Sri, variant: Variant, fen: FEN, multiPv: Int, path: String)(push: Push): Unit = {
|
def register(sri: Socket.Sri, variant: Variant, fen: FEN, multiPv: Int, path: String)(push: Push): Unit =
|
||||||
members get sri.value foreach { wm =>
|
if (setting.get()) {
|
||||||
unregisterEval(wm.setupId, sri)
|
members get sri.value foreach { wm =>
|
||||||
|
unregisterEval(wm.setupId, sri)
|
||||||
|
}
|
||||||
|
val setupId = makeSetupId(variant, fen, multiPv)
|
||||||
|
members += (sri.value -> WatchingMember(push, setupId, path))
|
||||||
|
evals += (setupId -> (~evals.get(setupId) + sri.value))
|
||||||
|
expirableSris put sri.value
|
||||||
}
|
}
|
||||||
val setupId = makeSetupId(variant, fen, multiPv)
|
|
||||||
members += (sri.value -> WatchingMember(push, setupId, path))
|
|
||||||
evals += (setupId -> (~evals.get(setupId) + sri.value))
|
|
||||||
expirableSris put sri.value
|
|
||||||
}
|
|
||||||
|
|
||||||
def onEval(input: EvalCacheEntry.Input, sri: Socket.Sri): Unit = {
|
def onEval(input: EvalCacheEntry.Input, sri: Socket.Sri): Unit = if (setting.get()) {
|
||||||
(1 to input.eval.multiPv) flatMap { multiPv =>
|
(1 to input.eval.multiPv) flatMap { multiPv =>
|
||||||
evals get makeSetupId(input.id.variant, input.fen, multiPv)
|
evals get makeSetupId(input.id.variant, input.fen, multiPv)
|
||||||
} foreach { sris =>
|
} foreach { sris =>
|
||||||
|
|
Loading…
Reference in New Issue