$stamp = (float)microtime(true);
$jobs = DBA::p("SELECT COUNT(*) AS `jobs` FROM `workerqueue` WHERE `done` AND `executed` > UTC_TIMESTAMP() - INTERVAL ? MINUTE", $interval);
self::$db_duration += (microtime(true) - $stamp);
- //self::$db_duration_stat += (microtime(true) - $stamp);
+ self::$db_duration_stat += (microtime(true) - $stamp);
if ($job = DBA::fetch($jobs)) {
$jobs_per_minute[$interval] = number_format($job['jobs'] / $interval, 0);
}
return $count;
}
+ /**
+ * @brief Returns waiting jobs for the current process id
+ *
+ * @return array waiting workerqueue jobs
+ * @throws \Exception
+ */
private static function getWaitingJobForPID()
{
$stamp = (float)microtime(true);
return false;
}
+ /**
+ * @brief Returns the next jobs that should be executed
+ *
+ * @return array array with next jobs
+ * @throws \Exception
+ */
private static function nextProcess()
{
$priority = self::nextPriority();
return $ids;
}
+ /**
+ * @brief Returns the priority of the next workerqueue job
+ *
+ * @return string priority
+ * @throws \Exception
+ */
private static function nextPriority()
{
$waiting = [];
// If there is no result we check without priority limit
if (empty($ids)) {
$stamp = (float)microtime(true);
- $result = DBA::select(
- 'workerqueue',
- ['id'],
- ["`pid` = 0 AND NOT `done` AND `next_try` < ?",
- DateTimeFormat::utcNow()],
- ['limit' => 1, 'order' => ['priority', 'created']]
- );
+ $condition = ["`pid` = 0 AND NOT `done` AND `next_try` < ?", DateTimeFormat::utcNow()];
+ $result = DBA::select('workerqueue', ['id'], $condition, ['limit' => 1, 'order' => ['priority', 'created']]);
self::$db_duration += (microtime(true) - $stamp);
while ($id = DBA::fetch($result)) {
if (!empty($ids)) {
$stamp = (float)microtime(true);
- $condition = "`id` IN (".substr(str_repeat("?, ", count($ids)), 0, -2).") AND `pid` = 0 AND NOT `done`";
- array_unshift($ids, $condition);
- DBA::update('workerqueue', ['executed' => DateTimeFormat::utcNow(), 'pid' => $mypid], $ids);
+ $condition = ['id' => $ids, 'done' => false, 'pid' => 0];
+ DBA::update('workerqueue', ['executed' => DateTimeFormat::utcNow(), 'pid' => $mypid], $condition);
self::$db_duration += (microtime(true) - $stamp);
self::$db_duration_write += (microtime(true) - $stamp);
}