Added function description

This commit is contained in:
Michael 2019-02-17 19:20:24 +00:00
parent 061d959e7f
commit a1a1367d6e
1 changed files with 23 additions and 11 deletions

View File

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