From 4b29937a741a9ea42df5db1571c42ac047ef2ead Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 13 Jul 2016 19:43:16 +0200 Subject: [PATCH] Worker: New value for cooldown time after each function call --- doc/htconfig.md | 1 + include/poller.php | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/doc/htconfig.md b/doc/htconfig.md index 2435da2baa..f7266604f6 100644 --- a/doc/htconfig.md +++ b/doc/htconfig.md @@ -67,6 +67,7 @@ line to your .htconfig.php: * throttle_limit_week - Maximum number of posts that a user can send per week with the API. * throttle_limit_month - Maximum number of posts that a user can send per month with the API. * wall-to-wall_share (Boolean) - Displays forwarded posts like "wall-to-wall" posts. +* worker_cooldown - Cooldown time after each worker function call. Default value is 0 seconds. * xrd_timeout - Timeout for fetching the XRD links. Default value is 20 seconds. ## service_class ## diff --git a/include/poller.php b/include/poller.php index d134f30d0f..9ea0aac1b3 100644 --- a/include/poller.php +++ b/include/poller.php @@ -10,6 +10,9 @@ if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) { chdir($directory); } +use \Friendica\Core\Config; +use \Friendica\Core\PConfig; + require_once("boot.php"); function poller_run(&$argv, &$argc){ @@ -58,6 +61,8 @@ function poller_run(&$argv, &$argc){ if (poller_too_much_workers(2)) return; + $cooldown = Config::get("system", "worker_cooldown", 0); + $starttime = time(); while ($r = q("SELECT * FROM `workerqueue` WHERE `executed` = '0000-00-00 00:00:00' ORDER BY `created` LIMIT 1")) { @@ -109,6 +114,11 @@ function poller_run(&$argv, &$argc){ logger("Process ".getmypid()." - ID ".$r[0]["id"].": ".$funcname." ".$r[0]["parameter"]); $funcname($argv, $argc); + if ($cooldown > 0) { + logger("Process ".getmypid()." - ID ".$r[0]["id"].": ".$funcname." - in cooldown for ".$cooldown." seconds"); + sleep($cooldown); + } + logger("Process ".getmypid()." - ID ".$r[0]["id"].": ".$funcname." - done"); q("DELETE FROM `workerqueue` WHERE `id` = %d", intval($r[0]["id"])); -- 2.39.5