Skip to content

Commit

Permalink
Fix queue in freeze.
Browse files Browse the repository at this point in the history
  • Loading branch information
kunyavskiy committed Apr 17, 2024
1 parent 59e936c commit a3e4460
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/backend/src/main/kotlin/org/icpclive/service/QueueService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ class QueueService : Service {
else -> settings.waitTime
}

private fun RunInfo.isInProgress(contestInfo: ContestInfo): Boolean {
return result is RunResult.InProgress && time < contestInfo.freezeTime
}


override fun CoroutineScope.runOn(flow: Flow<ContestStateWithScoreboard>) {
launch {
val featuredRunsFlow = MutableSharedFlow<FeaturedRunAction>(
Expand Down Expand Up @@ -144,7 +149,7 @@ class QueueService : Service {
// we want to update runs already in queue
run.id in runs -> true
// we can postpone untested run if there are too many untested runs
run.result is RunResult.InProgress && runs.values.count { it.result is RunResult.InProgress } >= contestInfo.queueSettings.maxUntestedRun -> false
run.isInProgress(contestInfo) && runs.values.count { it.isInProgress(contestInfo) } >= contestInfo.queueSettings.maxUntestedRun -> false
// otherwise, we are adding runs if they are not too old
else -> contestInfo.currentContestTime <= runUpdateTime + run.getTimeInQueue(contestInfo.queueSettings)
}
Expand Down Expand Up @@ -191,10 +196,11 @@ class QueueService : Service {
resultFlow.emit(QueueSnapshotEvent(runs.values.sortedBy { it.time }))
}
}
while (runs.size >= (currentContestInfo?.queueSettings?.maxQueueSize ?: 0)) {
val contestInfo = currentContestInfo ?: return@collect
while (runs.size >= contestInfo.queueSettings.maxQueueSize) {
runs.values.asSequence()
.filterNot { it.result.isFTS() || it.featuredRunMedia != null }
.filterNot { it.result is RunResult.InProgress }
.filterNot { it.isInProgress(contestInfo) }
.minByOrNull { lastUpdateTime[it.id]!! }
?.run { removeRun(this) }
?: break
Expand Down

0 comments on commit a3e4460

Please sign in to comment.