regroup functions under Maintenance class

This commit is contained in:
Thibault Duplessis 2013-09-26 18:25:55 +02:00
parent 6efaa1e81c
commit b62aebb082
5 changed files with 36 additions and 45 deletions

View file

@ -50,7 +50,7 @@ object Setup extends LilaController with TheftPrevention {
OptionResult(GameRepo game gameId) { game
if (game.started) BadRequest("Cannot decline started challenge")
else {
Env.game remover game.id
Env.game.maintenance remove game.id
Env.hub.actor.challenger ! lila.hub.actorApi.setup.DeclineChallenge(gameId)
Ok("ok")
}
@ -118,7 +118,7 @@ object Setup extends LilaController with TheftPrevention {
OptionResult(GameRepo pov fullId) { pov
if (pov.game.started) Redirect(routes.Round.player(pov.fullId))
else {
Env.game remover pov.game.id
Env.game.maintenance remove pov.game.id
Redirect(routes.Lobby.home)
}
}

View file

@ -67,10 +67,10 @@ final class Env(
import scala.concurrent.duration._
scheduler.effect(0.9 hours, "game: cleanup") {
titivate.cleanupUnplayed
maintenance.cleanupUnplayed
}
scheduler.once(10 seconds) {
titivate.cleanupUnplayed
maintenance.cleanupUnplayed
}
scheduler.message(10.seconds) {
@ -89,9 +89,7 @@ final class Env(
private lazy val computeElos = new ComputeElos(system)
private lazy val titivate = new Titivate(remover, scheduler)
lazy val remover = new Remover(hub.actor.bookmark)
lazy val maintenance = new Maintenance(scheduler, hub.actor.bookmark)
private def jsPath =
"%s/%s".format(appPath, isProd.fold(JsPathCompiled, JsPathRaw))

View file

@ -0,0 +1,31 @@
package lila.game
import scala.concurrent.duration._
import play.api.libs.json._
import lila.common.Scheduler
import lila.db.api._
import lila.hub.actorApi.bookmark.Remove
import tube.gameTube
private[game] final class Maintenance(
scheduler: Scheduler,
bookmark: akka.actor.ActorSelection) {
def remove(ids: List[GameRepo.ID]) {
$remove[Game]($select byIds ids)
PgnRepo removeIds ids
bookmark ! Remove(ids)
}
def remove(id: GameRepo.ID) {
remove(id :: Nil)
}
def cleanupUnplayed: Funit =
$primitive(Query.unplayed, "_id", max = 10000.some)(_.asOpt[String]) addEffect { ids
println("[titivate] Remove %d unplayed games" format ids.size)
scheduler.throttle(1.second)(ids grouped 20 toSeq)(remove)
} void
}

View file

@ -1,18 +0,0 @@
package lila.game
import lila.db.api._
import lila.hub.actorApi.bookmark.Remove
import tube.gameTube
private[game] final class Remover(bookmark: akka.actor.ActorSelection) {
def apply(ids: List[GameRepo.ID]) {
$remove[Game]($select byIds ids)
PgnRepo removeIds ids
bookmark ! Remove(ids)
}
def apply(id: GameRepo.ID) {
apply(id :: Nil)
}
}

View file

@ -1,20 +0,0 @@
package lila.game
import scala.concurrent.duration._
import play.api.libs.json._
import lila.common.Scheduler
import lila.db.api._
import tube.gameTube
private[game] final class Titivate(
remover: Remover,
scheduler: Scheduler) {
def cleanupUnplayed: Funit =
$primitive(Query.unplayed, "_id", max = 10000.some)(_.asOpt[String]) addEffect { ids
println("[titivate] Remove %d unplayed games" format ids.size)
scheduler.throttle(1.second)(ids grouped 100 toSeq)(remover.apply)
} void
}