static cooldown moved to the cooldown function

This commit is contained in:
Michael 2022-09-22 22:46:59 +00:00
parent e1341b6ad3
commit 97e5477bde
2 changed files with 11 additions and 12 deletions

View file

@ -481,6 +481,16 @@ class Worker
*/
public static function coolDown()
{
$cooldown = DI::config()->get('system', 'worker_cooldown', 0);
if ($cooldown > 0) {
Logger::debug('Wait for cooldown.', ['cooldown' => $cooldown]);
if ($cooldown < 1) {
usleep($cooldown * 1000000);
} else {
sleep($cooldown);
}
}
$load_cooldown = DI::config()->get('system', 'worker_load_cooldown');
$processes_cooldown = DI::config()->get('system', 'worker_processes_cooldown');
@ -529,12 +539,6 @@ class Worker
{
$a = DI::app();
$cooldown = DI::config()->get('system', 'worker_cooldown', 0);
if ($cooldown > 0) {
Logger::notice('Pre execution cooldown.', ['cooldown' => $cooldown, 'id' => $queue['id'], 'priority' => $queue['priority'], 'command' => $queue['command']]);
sleep($cooldown);
}
self::coolDown();
Logger::enableWorker($funcname);
@ -605,11 +609,6 @@ class Worker
Logger::info('Process done.', ['priority' => $queue['priority'], 'id' => $queue['id'], 'duration' => round($duration, 3)]);
DI::profiler()->saveLog(DI::logger(), 'ID ' . $queue['id'] . ': ' . $funcname);
if ($cooldown > 0) {
Logger::info('Post execution cooldown.', ['priority' => $queue['priority'], 'id' => $queue['id'], 'cooldown' => $cooldown]);
sleep($cooldown);
}
}
/**

View file

@ -615,7 +615,7 @@ return [
// Minimum for this config value is 1. Maximum is 64 as the resulting profile URL mustn't be longer than 255 chars.
'username_max_length' => 48,
// worker_cooldown (Integer)
// worker_cooldown (Float)
// Cooldown period in seconds before each worker function call.
'worker_cooldown' => 0,