Merge pull request #2677 from annando/1607-worker-cooldown

Worker: New value for cooldown time after each function call
This commit is contained in:
Tobias Diekershoff 2016-07-14 00:26:26 +02:00 committed by GitHub
commit 0ff8b555fd
2 changed files with 11 additions and 0 deletions

View file

@ -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_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. * 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. * 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. * xrd_timeout - Timeout for fetching the XRD links. Default value is 20 seconds.
## service_class ## ## service_class ##

View file

@ -10,6 +10,9 @@ if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
chdir($directory); chdir($directory);
} }
use \Friendica\Core\Config;
use \Friendica\Core\PConfig;
require_once("boot.php"); require_once("boot.php");
function poller_run(&$argv, &$argc){ function poller_run(&$argv, &$argc){
@ -58,6 +61,8 @@ function poller_run(&$argv, &$argc){
if (poller_too_much_workers(2)) if (poller_too_much_workers(2))
return; return;
$cooldown = Config::get("system", "worker_cooldown", 0);
$starttime = time(); $starttime = time();
while ($r = q("SELECT * FROM `workerqueue` WHERE `executed` = '0000-00-00 00:00:00' ORDER BY `created` LIMIT 1")) { 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"]); logger("Process ".getmypid()." - ID ".$r[0]["id"].": ".$funcname." ".$r[0]["parameter"]);
$funcname($argv, $argc); $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"); logger("Process ".getmypid()." - ID ".$r[0]["id"].": ".$funcname." - done");
q("DELETE FROM `workerqueue` WHERE `id` = %d", intval($r[0]["id"])); q("DELETE FROM `workerqueue` WHERE `id` = %d", intval($r[0]["id"]));