+ }
+ return $passing_slow;
+}
+
+/**
+ * @brief Find and claim the next worker process for us
+ *
+ * @return boolean Have we found something?
+ */
+function find_worker_processes() {
+ // Check if we should pass some low priority process
+ $highest_priority = 0;
+ $found = false;
+
+ if (poller_passing_slow($highest_priority)) {
+ // Are there waiting processes with a higher priority than the currently highest?
+ $result = dba::p("UPDATE `workerqueue` SET `executed` = ?, `pid` = ?
+ WHERE `executed` <= ? AND `priority` < ?
+ ORDER BY `priority`, `created` LIMIT 5",
+ datetime_convert(), getmypid(), NULL_DATE, $highest_priority);
+ if (dbm::is_result($result)) {
+ $found = (dba::num_rows($result) > 0);
+ }
+ dba::close($result);
+
+ if (!$found) {
+ // Give slower processes some processing time
+ $result = dba::p("UPDATE `workerqueue` SET `executed` = ?, `pid` = ?
+ WHERE `executed` <= ? AND `priority` > ?
+ ORDER BY `priority`, `created` LIMIT 1",
+ datetime_convert(), getmypid(), NULL_DATE, $highest_priority);
+ if (dbm::is_result($result)) {
+ $found = (dba::num_rows($result) > 0);
+ }
+ dba::close($result);
+ }
+ }