@@ -1583,40 +1583,42 @@ public function getJudgeTasksAction(Request $request): array
1583
1583
// This is case 2.a) from above: start something new.
1584
1584
// This runs transactional to prevent a queue task being picked up twice.
1585
1585
$ judgetasks = null ;
1586
- $ this ->em ->wrapInTransaction (function () use ($ judgehost , $ max_batchsize , &$ judgetasks ) {
1587
- $ jobid = $ this ->em ->createQueryBuilder ()
1588
- ->from (QueueTask::class, 'qt ' )
1589
- ->innerJoin ('qt.judging ' , 'j ' )
1590
- ->select ('j.judgingid ' )
1586
+ $ jobid = $ this ->em ->createQueryBuilder ()
1587
+ ->from (QueueTask::class, 'qt ' )
1588
+ ->innerJoin ('qt.judging ' , 'j ' )
1589
+ ->select ('j.judgingid ' )
1590
+ ->andWhere ('qt.startTime IS NULL ' )
1591
+ ->addOrderBy ('qt.priority ' )
1592
+ ->addOrderBy ('qt.teamPriority ' )
1593
+ ->setMaxResults (1 )
1594
+ ->getQuery ()
1595
+ ->getOneOrNullResult (AbstractQuery::HYDRATE_SINGLE_SCALAR );
1596
+ if ($ jobid !== null ) {
1597
+ // Mark it as being worked on.
1598
+ $ result = $ this ->em ->createQueryBuilder ()
1599
+ ->update (QueueTask::class, 'qt ' )
1600
+ ->set ('qt.startTime ' , Utils::now ())
1601
+ ->andWhere ('qt.judging = :jobid ' )
1591
1602
->andWhere ('qt.startTime IS NULL ' )
1592
- ->addOrderBy ('qt.priority ' )
1593
- ->addOrderBy ('qt.teamPriority ' )
1594
- ->setMaxResults (1 )
1603
+ ->setParameter ('jobid ' , $ jobid )
1595
1604
->getQuery ()
1596
- ->getOneOrNullResult (AbstractQuery::HYDRATE_SINGLE_SCALAR );
1597
- if ($ jobid === null ) {
1598
- return ;
1599
- }
1600
- $ judgetasks = $ this ->getJudgetasks ($ jobid , $ max_batchsize , $ judgehost );
1601
- if (empty ($ judgetasks )) {
1602
- // Somehow we got ourselves in a situation that there was a queue task without remaining judge tasks.
1603
- // This should not happen, but if it does, we need to clean up. Each of the fetch-work calls will clean
1604
- // up one queue task. We need to signal to the judgehost that there might be more work to do.
1605
+ ->execute ();
1606
+
1607
+ if ($ result == 0 ) {
1608
+ // Another judgehost beat us to it.
1605
1609
$ judgetasks = [['type ' => 'try_again ' ]];
1606
1610
} else {
1607
- // Mark it as being worked on.
1608
- $ this ->em ->createQueryBuilder ()
1609
- ->update (QueueTask::class, 'qt ' )
1610
- ->set ('qt.startTime ' , Utils::now ())
1611
- ->andWhere ('qt.judging = :jobid ' )
1612
- ->andWhere ('qt.startTime IS NULL ' )
1613
- ->setParameter ('jobid ' , $ jobid )
1614
- ->getQuery ()
1615
- ->execute ();
1611
+ $ judgetasks = $ this ->getJudgetasks ($ jobid , $ max_batchsize , $ judgehost );
1612
+ if (empty ($ judgetasks )) {
1613
+ // Somehow we got ourselves in a situation that there was a queue task without remaining judge tasks.
1614
+ // This should not happen, but if it does, we need to clean up. Each of the fetch-work calls will clean
1615
+ // up one queue task. We need to signal to the judgehost that there might be more work to do.
1616
+ $ judgetasks = [['type ' => 'try_again ' ]];
1617
+ }
1618
+ }
1619
+ if (!empty ($ judgetasks )) {
1620
+ return $ judgetasks ;
1616
1621
}
1617
- });
1618
- if (!empty ($ judgetasks )) {
1619
- return $ judgetasks ;
1620
1622
}
1621
1623
1622
1624
if ($ this ->config ->get ('enable_parallel_judging ' )) {
0 commit comments