live setting for tournament pairing parallelism

This commit is contained in:
Thibault Duplessis 2020-04-14 14:54:49 -06:00
parent 3a6f0961ee
commit 7d2d486d2f
3 changed files with 18 additions and 5 deletions

View file

@ -17,7 +17,8 @@ final class Dev(env: Env) extends LilaController(env) {
env.streamer.alwaysFeaturedSetting,
env.rating.ratingFactorsSetting,
env.plan.donationGoalSetting,
env.apiTimelineSetting
env.apiTimelineSetting,
env.tournament.pairingParallelismSetting
)
def settings = Secure(_.Settings) { implicit ctx => _ =>

View file

@ -35,7 +35,8 @@ final class Env(
onStart: lila.round.OnStart,
historyApi: lila.history.HistoryApi,
trophyApi: lila.user.TrophyApi,
remoteSocketApi: lila.socket.RemoteSocket
remoteSocketApi: lila.socket.RemoteSocket,
settingStore: lila.memo.SettingStore.Builder
)(
implicit
ec: scala.concurrent.ExecutionContext,
@ -104,6 +105,12 @@ final class Env(
lazy val getTourName = new GetTourName((id, lang) => cached.nameCache.sync(id -> lang))
lazy val pairingParallelismSetting = settingStore[Int](
"pairingParallelism",
default = 1,
text = "Parallelism factor of tournament pairing".some
)
lila.common.Bus.subscribe(
system.actorOf(Props(wire[ApiActor]), name = config.apiActorName),
"finishGame",
@ -113,7 +120,11 @@ final class Env(
)
system.actorOf(Props(wire[CreatedOrganizer]))
system.actorOf(Props(wire[StartedOrganizer]))
system.actorOf(Props {
def mk = (parallelism: () => Int) => wire[StartedOrganizer]
mk(pairingParallelismSetting.get _)
})
private lazy val schedulerActor = system.actorOf(Props(wire[TournamentScheduler]))
scheduler.scheduleWithFixedDelay(1 minute, 5 minutes) { () =>

View file

@ -9,7 +9,8 @@ final private class StartedOrganizer(
api: TournamentApi,
tournamentRepo: TournamentRepo,
playerRepo: PlayerRepo,
socket: TournamentSocket
socket: TournamentSocket,
parallelism: () => Int
)(implicit mat: akka.stream.Materializer)
extends Actor {
@ -35,7 +36,7 @@ final private class StartedOrganizer(
case Tick =>
tournamentRepo.startedCursor
.documentSource()
.mapAsync(1) { tour =>
.mapAsync(parallelism()) { tour =>
processTour(tour) recover {
case e: Exception =>
logger.error(s"StartedOrganizer $tour", e)