- if (!$found && self::passingSlow($highest_priority)) {
- // Are there waiting processes with a higher priority than the currently highest?
- $stamp = (float)microtime(true);
- $result = DBA::select(
- 'workerqueue',
- ['id'],
- ["`pid` = 0 AND `priority` < ? AND NOT `done` AND `next_try` < ?",
- $highest_priority, DateTimeFormat::utcNow()],
- ['limit' => 1, 'order' => ['priority', 'created']]
- );
- self::$db_duration += (microtime(true) - $stamp);
-
- while ($id = DBA::fetch($result)) {
- $ids[] = $id["id"];
- }
- DBA::close($result);
-
- $found = (count($ids) > 0);
-
- if (!$found) {
- // Give slower processes some processing time
- $stamp = (float)microtime(true);
- $result = DBA::select(
- 'workerqueue',
- ['id'],
- ["`pid` = 0 AND `priority` > ? AND NOT `done` AND `next_try` < ?",
- $highest_priority, DateTimeFormat::utcNow()],
- ['limit' => 1, 'order' => ['priority', 'created']]
- );
- self::$db_duration += (microtime(true) - $stamp);
-
- while ($id = DBA::fetch($result)) {
- $ids[] = $id["id"];
- }
- DBA::close($result);
-
- $found = (count($ids) > 0);
- $passing_slow = $found;
- }
- }
-
- // At first try to fetch a bunch of high or medium tasks
- if (!$found && ($limit > 1)) {
- $stamp = (float)microtime(true);
- $result = DBA::select(
- 'workerqueue',
- ['id'],
- ["`pid` = 0 AND NOT `done` AND `priority` <= ? AND `next_try` < ? AND `retrial` = 0",
- PRIORITY_MEDIUM, DateTimeFormat::utcNow()],
- ['limit' => $limit, 'order' => ['created']]
- );
- self::$db_duration += (microtime(true) - $stamp);
-
- while ($id = DBA::fetch($result)) {
- $ids[] = $id["id"];
- }
- DBA::close($result);
-
- $found = (count($ids) > 0);
- }