Skip to content

Commit 157de77

Browse files
committed
Addressed @lucaro 's comments regarding priority-based dequeue of judgement validators. Untested.
1 parent 2802c5d commit 157de77

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

backend/src/main/kotlin/dev/dres/api/rest/handler/judgement/DequeueJudgementHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class DequeueJudgementHandler : AbstractJudgementHandler(),
5353
private fun nextRequest(ctx: Context): ApiJudgementRequest? {
5454
val evaluationManager = ctx.eligibleManagerForId<RunManager>()
5555
checkEligibility(ctx, evaluationManager)
56-
val validator = evaluationManager.judgementValidators.find { it.hasOpen } ?: return null
56+
val validator = evaluationManager.judgementValidators.sortedBy { it.priority }.find { it.hasOpen } ?: return null
5757
val next = validator.next() ?: return null
5858
val taskDescription = validator.taskTemplate.textualDescription()
5959
return ApiJudgementRequest(

backend/src/main/kotlin/dev/dres/api/rest/handler/judgement/DequeueVoteHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class DequeueVoteHandler: AbstractJudgementHandler(), GetRestHandler<ApiJudgemen
5252
fun nextRequest(ctx: Context): ApiJudgementRequest? { //TODO needs adjustment to deal with answerSets
5353
val evaluationManager = ctx.eligibleManagerForId<RunManager>()
5454

55-
val validator = evaluationManager.judgementValidators.filterIsInstance<VoteValidator>().find { it.isActive } ?: return null
55+
val validator = evaluationManager.judgementValidators.filterIsInstance<VoteValidator>().sortedBy { it.priority }.find { it.isActive } ?: return null
5656
val next = validator.next()
5757
?: /* No submission awaiting judgement */
5858
return null

backend/src/main/kotlin/dev/dres/run/validation/interfaces/JudgementValidator.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ interface JudgementValidator {
3131
/** The template of the task this validator belongs to */
3232
val taskTemplate: ApiTaskTemplate
3333

34+
/** The priority of this [JudgementValidator], higher priorities are represent by a higher number and consumers are expected to respect this */
35+
val priority: Int
36+
3437
/**
3538
* Retrieves and returns the next element that requires a verdict from this [JudgementValidator]'s internal queue.
3639
*

backend/src/main/kotlin/dev/dres/run/validation/judged/BasicJudgementValidator.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,23 @@ open class BasicJudgementValidator(
3939
private val counter = AtomicInteger()
4040
private const val judgementTimeout = 60_000 //ms until a request is re-scheduled
4141

42+
private const val defaultPriority = 0;
43+
4244
/**
4345
* The key used to read the task type configuration order
4446
* The value expected under this key is LIFO, which results in LIFO ordering of the queue,
4547
* all other parameters or the absence of one results in the default FIFO behaviour.
4648
*/
4749
private const val CONFIGURATION_ORDER_KEY = "JUDGEMENT.order"
50+
51+
/**
52+
* The key used to read the task type configuration priority.
53+
* The value is expected to be a number. Higher number represents higher priority.
54+
* Consumers are expected to respect the {priority}
55+
*/
56+
private const val CONFIGURATION_PRIORITY_KEY = "JUDGEMENT.priority"
57+
58+
4859
}
4960

5061
/** The [BasicJudgementValidator]'s ID is simply an auto-incrementing number. */
@@ -53,6 +64,9 @@ open class BasicJudgementValidator(
5364
/** A [BasicJudgementValidator] is always deferring. */
5465
override val deferring: Boolean = true
5566

67+
/** The priority of this [JudgementValidator], higher priorities are represent by a higher number and consumers are expected to respect this */
68+
override val priority = this.taskType.configuration[CONFIGURATION_PRIORITY_KEY]?.toInt() ?: defaultPriority
69+
5670
/** Internal lock on relevant data structures. */
5771
private val updateLock = ReentrantReadWriteLock()
5872

0 commit comments

Comments
 (0)