Let the worker run for an hour in daemon mode
This commit is contained in:
parent
74d7d7e164
commit
69c7e9af20
|
@ -224,7 +224,9 @@ while (true) {
|
|||
usleep($sleep);
|
||||
|
||||
$pid = pcntl_waitpid(-1, $status, WNOHANG);
|
||||
Logger::info('Checked children status via pcntl_waitpid', ['pid' => $pid, 'status' => $status]);
|
||||
if ($pid > 0) {
|
||||
Logger::info('Children quit via pcntl_waitpid', ['pid' => $pid, 'status' => $status]);
|
||||
}
|
||||
|
||||
$timeout = ($seconds >= $wait_interval);
|
||||
} while (!$timeout && !Worker::IPCJobsExists());
|
||||
|
|
|
@ -94,7 +94,10 @@ class Worker
|
|||
|
||||
$last_check = $starttime = time();
|
||||
self::$state = self::STATE_STARTUP;
|
||||
$wait_interval = self::isDaemonMode() ? 360 : 10;
|
||||
$start = time();
|
||||
|
||||
do {
|
||||
// We fetch the next queue entry that is about to be executed
|
||||
while ($r = self::workerProcess()) {
|
||||
// Don't refetch when a worker fetches tasks for multiple workers
|
||||
|
@ -154,8 +157,39 @@ class Worker
|
|||
}
|
||||
return;
|
||||
}
|
||||
$start = time();
|
||||
}
|
||||
|
||||
$seconds = (time() - $start);
|
||||
|
||||
// logarithmic wait time calculation.
|
||||
$arg = (($seconds + 1) / ($wait_interval / 9)) + 1;
|
||||
$sleep = min(1000000, round(log10($arg) * 1000000, 0));
|
||||
usleep($sleep);
|
||||
|
||||
$timeout = ($seconds >= $wait_interval);
|
||||
Logger::info('Timeout', ['timeout' => $timeout, 'seconds' => $seconds, 'sleep' => $sleep]);
|
||||
|
||||
if (!$timeout) {
|
||||
if (DI::process()->isMaxLoadReached()) {
|
||||
Logger::notice('maximum load reached, quitting.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Kill stale processes every 5 minutes
|
||||
$last_cleanup = DI::config()->get('system', 'worker_last_cleaned', 0);
|
||||
if (time() > ($last_cleanup + 300)) {
|
||||
DI::config()->set('system', 'worker_last_cleaned', time());
|
||||
self::killStaleWorkers();
|
||||
}
|
||||
|
||||
// Check if the system is ready
|
||||
if (!self::isReady()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} while (!$timeout);
|
||||
|
||||
// Cleaning up. Possibly not needed, but it doesn't harm anything.
|
||||
if (self::isDaemonMode()) {
|
||||
self::IPCSetJobState(false);
|
||||
|
|
Loading…
Reference in a new issue