no longer expire simuls without a host

pull/6333/head
Thibault Duplessis 2020-04-06 17:29:28 -05:00
parent 5c2b4f91bf
commit a0a2b44e1e
4 changed files with 2 additions and 25 deletions

View File

@ -75,7 +75,7 @@ final class Simul(
def hostPing(simulId: String) = Open { implicit ctx =>
AsHost(simulId) { simul =>
env.simul.cleaner hostPing simul inject jsonOkResult
env.simul.repo setHostSeenNow simul inject jsonOkResult
}
}

View File

@ -69,8 +69,6 @@ final class Env(
def version(simulId: Simul.ID) =
simulSocket.rooms.ask[SocketVersion](simulId)(GetVersion)
lazy val cleaner = new SimulCleaner(repo, api)
Bus.subscribeFuns(
"finishGame" -> {
case lila.game.actorApi.FinishGame(game, _, _) => api finishGame game
@ -92,6 +90,4 @@ final class Env(
)
}
)
system.scheduler.scheduleWithFixedDelay(30 seconds, 30 seconds)(() => cleaner.cleanUp)
}

View File

@ -1,19 +0,0 @@
package lila.simul
import org.joda.time.DateTime
final private[simul] class SimulCleaner(
repo: SimulRepo,
api: SimulApi
)(implicit ec: scala.concurrent.ExecutionContext) {
def cleanUp: Funit = repo.allCreated.map {
_ foreach { simul =>
val minutesAgo = DateTime.now.minusMinutes(2)
if (simul.createdAt.isBefore(minutesAgo) &&
!simul.hostSeenAt.exists(_ isAfter minutesAgo)) api.abort(simul.id)
}
}
def hostPing(simul: Simul) = repo setHostSeenNow simul
}

View File

@ -50,7 +50,7 @@ module.exports = function(env) {
this.hostPing = () => {
if (simul.createdByMe(this) && this.data.isCreated) {
xhr.ping(this);
setTimeout(this.hostPing, 20000);
setTimeout(this.hostPing, 10000);
}
};
this.hostPing();