add support for fishnet abort
parent
9d94f0151f
commit
b622d733f2
|
@ -29,6 +29,11 @@ object Fishnet extends LilaController {
|
|||
api.postAnalysis(Work.Id(workId), client, data) >> api.acquire(client)
|
||||
}
|
||||
|
||||
def abort(workId: String) = ClientAction[JsonApi.Request.Acquire] { req =>
|
||||
client =>
|
||||
api.abort(Work.Id(workId), client) inject none
|
||||
}
|
||||
|
||||
private def ClientAction[A <: JsonApi.Request](f: A => lila.fishnet.Client => Fu[Option[JsonApi.Work]])(implicit reads: Reads[A]) =
|
||||
Action.async(BodyParsers.parse.tolerantJson) { req =>
|
||||
req.body.validate[A].fold(
|
||||
|
|
|
@ -212,6 +212,7 @@ GET /game/export/png/$gameId<\w{8}>.png controllers.Export.png(gameId: Str
|
|||
POST /fishnet/acquire controllers.Fishnet.acquire
|
||||
POST /fishnet/move/$workId<\w{8}> controllers.Fishnet.move(workId: String)
|
||||
POST /fishnet/analysis/$workId<\w{8}> controllers.Fishnet.analysis(workId: String)
|
||||
POST /fishnet/abort/$workId<\w{8}> controllers.Fishnet.abort(workId: String)
|
||||
|
||||
# Pref
|
||||
POST /pref/:name controllers.Pref.set(name: String)
|
||||
|
|
|
@ -229,9 +229,11 @@ object mon {
|
|||
object fishnet {
|
||||
object client {
|
||||
def result(client: String, skill: String) = new {
|
||||
def success = inc(s"fishnet.client.result.$skill.$client.success")
|
||||
def failure = inc(s"fishnet.client.result.$skill.$client.failure")
|
||||
def timeout = inc(s"fishnet.client.result.$skill.$client.timeout")
|
||||
def success = apply("success")
|
||||
def failure = apply("failure")
|
||||
def timeout = apply("timeout")
|
||||
def abort = apply("abort")
|
||||
private def apply(r: String) = inc(s"fishnet.client.result.$skill.$client.$r")
|
||||
}
|
||||
def time(client: String, skill: String) = rec(s"fishnet.client.time.$skill.$client")
|
||||
|
||||
|
|
|
@ -65,11 +65,11 @@ final class FishnetApi(
|
|||
funit
|
||||
case Some(work) => data.move.uci match {
|
||||
case Some(uci) =>
|
||||
monitor.move(client, work)
|
||||
monitor.move(work, client)
|
||||
hub.actor.roundMap ! hubApi.map.Tell(work.game.id, hubApi.round.FishnetPlay(uci, work.currentFen))
|
||||
repo.deleteMove(work)
|
||||
case _ =>
|
||||
monitor.failure(client, work)
|
||||
monitor.failure(work, client)
|
||||
log.warn(s"Received invalid move ${data.move} by ${client.fullId}")
|
||||
repo.updateOrGiveUpMove(work.invalid)
|
||||
}
|
||||
|
@ -82,17 +82,26 @@ final class FishnetApi(
|
|||
log.warn(s"Received unknown or unacquired analysis $workId by ${client.fullId}")
|
||||
fuccess(none)
|
||||
case Some(work) => AnalysisBuilder(client, work, data) flatMap { analysis =>
|
||||
monitor.analysis(client, work, data)
|
||||
monitor.analysis(work, client, data)
|
||||
repo.deleteAnalysis(work) inject analysis.some
|
||||
} recoverWith {
|
||||
case e: Exception =>
|
||||
monitor.failure(client, work)
|
||||
monitor.failure(work, client)
|
||||
log.warn(s"Received invalid analysis $workId by ${client.fullId}: ${e.getMessage}")
|
||||
repo.updateOrGiveUpAnalysis(work.invalid) inject none
|
||||
}
|
||||
}
|
||||
} flatMap { _ ?? saveAnalysis }
|
||||
|
||||
def abort(workId: Work.Id, client: Client): Funit = sequencer.analysis {
|
||||
repo.getAnalysis(workId).map(_.filter(_ isAcquiredBy client)) flatMap {
|
||||
_ ?? { work =>
|
||||
monitor.abort(work, client)
|
||||
repo.updateAnalysis(work.abort)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private[fishnet] def createClient(userId: Client.UserId, skill: String): Fu[Client] =
|
||||
Client.Skill.byKey(skill).fold(fufail[Client](s"Invalid skill $skill")) { sk =>
|
||||
val client = Client(
|
||||
|
|
|
@ -10,8 +10,8 @@ private final class Monitor(
|
|||
repo: FishnetRepo,
|
||||
scheduler: lila.common.Scheduler) {
|
||||
|
||||
private[fishnet] def analysis(client: Client, work: Work, result: JsonApi.Request.PostAnalysis) = {
|
||||
success(client, work)
|
||||
private[fishnet] def analysis(work: Work, client: Client, result: JsonApi.Request.PostAnalysis) = {
|
||||
success(work, client)
|
||||
val monitor = lila.mon.fishnet.analysis by client.userId.value
|
||||
monitor move result.analysis.size
|
||||
sample(result.analysis.filterNot(_.checkmate), 20).foreach { move =>
|
||||
|
@ -23,11 +23,11 @@ private final class Monitor(
|
|||
}
|
||||
}
|
||||
|
||||
private[fishnet] def move(client: Client, work: Work) = success(client, work)
|
||||
private[fishnet] def move(work: Work, client: Client) = success(work, client)
|
||||
|
||||
private def sample[A](elems: List[A], n: Int) = scala.util.Random shuffle elems take n
|
||||
|
||||
private def success(client: Client, work: Work) = {
|
||||
private def success(work: Work, client: Client) = {
|
||||
|
||||
lila.mon.fishnet.client.result(client.userId.value, work.skill.key).success()
|
||||
|
||||
|
@ -47,12 +47,15 @@ private final class Monitor(
|
|||
}
|
||||
}
|
||||
|
||||
private[fishnet] def failure(client: Client, work: Work) =
|
||||
private[fishnet] def failure(work: Work, client: Client) =
|
||||
lila.mon.fishnet.client.result(client.userId.value, work.skill.key).failure()
|
||||
|
||||
private[fishnet] def timeout(client: Client, work: Work) =
|
||||
private[fishnet] def timeout(work: Work, client: Client) =
|
||||
lila.mon.fishnet.client.result(client.userId.value, work.skill.key).timeout()
|
||||
|
||||
private[fishnet] def abort(work: Work, client: Client) =
|
||||
lila.mon.fishnet.client.result(client.userId.value, work.skill.key).abort()
|
||||
|
||||
private def monitorClients: Unit = repo.allClients map { clients =>
|
||||
|
||||
import lila.mon.fishnet.client._
|
||||
|
|
|
@ -94,6 +94,8 @@ object Work {
|
|||
|
||||
def isOutOfTries = tries >= 2
|
||||
|
||||
def abort = copy(acquired = none)
|
||||
|
||||
override def toString = s"id:$id game:${game.id} tries:$tries requestedBy:$sender acquired:$acquired"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue