From 97e5477bde1b4d88cca3eec6f35c4be855f576f1 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 22 Sep 2022 22:46:59 +0000 Subject: [PATCH] static cooldown moved to the cooldown function --- src/Core/Worker.php | 21 ++++++++++----------- static/defaults.config.php | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 6bf6168b2..036f065d4 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -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); - } } /** diff --git a/static/defaults.config.php b/static/defaults.config.php index fb6727491..b02f53774 100644 --- a/static/defaults.config.php +++ b/static/defaults.config.php @@ -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,