]> git.mxchange.org Git - friendica.git/commitdiff
static cooldown moved to the cooldown function
authorMichael <heluecht@pirati.ca>
Thu, 22 Sep 2022 22:46:59 +0000 (22:46 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 22 Sep 2022 22:46:59 +0000 (22:46 +0000)
src/Core/Worker.php
static/defaults.config.php

index 6bf6168b2fa2835913f6ac6e0645d525fda37bff..036f065d421368677f8608f61034a8df413a0776 100644 (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);
-               }
        }
 
        /**
index fb6727491bece70c544608c2da9978a82e573a72..b02f5377452e99c19d42bdc49f527efc71a74963 100644 (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,