aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2019-01-09 10:30:44 +0100
committerMario Vavti <mario@mariovavti.com>2019-01-09 10:30:44 +0100
commit217c2cacaf4bb97e41fc5c084561dd077d5a90b2 (patch)
tree71890707ddc1ab9b3784992a0907cf9289c0a4b8
parent06beb596283ee999e6b95b4a5eec9a6f948af962 (diff)
parentdf4b6f03769da35d086271279c709d0f6878ffc8 (diff)
downloadvolse-hubzilla-217c2cacaf4bb97e41fc5c084561dd077d5a90b2.tar.gz
volse-hubzilla-217c2cacaf4bb97e41fc5c084561dd077d5a90b2.tar.bz2
volse-hubzilla-217c2cacaf4bb97e41fc5c084561dd077d5a90b2.zip
Merge branch 'dev' into core_gallery_05
-rw-r--r--Zotlabs/Daemon/Master.php129
-rw-r--r--Zotlabs/Lib/Apps.php4
-rw-r--r--Zotlabs/Lib/PConfig.php17
-rw-r--r--doc/hook/daemon_master_release.bb5
-rw-r--r--doc/hooklist.bb3
5 files changed, 33 insertions, 125 deletions
diff --git a/Zotlabs/Daemon/Master.php b/Zotlabs/Daemon/Master.php
index 0656ca05b..857d47243 100644
--- a/Zotlabs/Daemon/Master.php
+++ b/Zotlabs/Daemon/Master.php
@@ -16,8 +16,6 @@ if(array_search( __file__ , get_included_files()) === 0) {
class Master {
- static public $queueworker = null;
-
static public function Summon($arr) {
proc_run('php','Zotlabs/Daemon/Master.php',$arr);
}
@@ -25,126 +23,21 @@ class Master {
static public function Release($argc,$argv) {
cli_startup();
- $maxworkers = get_config('system','max_queue_workers');
-
- if (!$maxworkers || $maxworkers == 0) {
- logger('Master: release: ' . print_r($argv,true), LOGGER_ALL,LOG_DEBUG);
- $cls = '\\Zotlabs\\Daemon\\' . $argv[0];
- $cls::run($argc,$argv);
- self::ClearQueue();
- } else {
- logger('Master: enqueue: ' . print_r($argv,true), LOGGER_ALL,LOG_DEBUG);
- $workinfo = ['argc'=>$argc,'argv'=>$argv];
- q("insert into config (cat,k,v) values ('queuework','%s','%s')",
- dbesc(uniqid('workitem:',true)),
- dbesc(serialize($workinfo)));
- self::Process();
- }
- }
-
- static public function GetWorkerID() {
- $maxworkers = get_config('system','max_queue_workers');
- $maxworkers = ($maxworkers) ? $maxworkers : 3;
-
- $workermaxage = get_config('system','max_queue_worker_age');
- $workermaxage = ($workermaxage) ? $workermaxage : 300;
-
- $workers = q("select * from config where cat='queueworkers' and k like '%s'", 'workerstarted_%');
-
- if (count($workers) > $maxworkers) {
- foreach ($workers as $idx => $worker) {
- $curtime = time();
- $age = (intval($curtime) - intval($worker['v']));
- if ( $age > $workermaxage) {
- logger("Prune worker: ".$worker['k'], LOGGER_ALL, LOGGER_DEBUG);
- $k = explode('_',$worker['k']);
- q("delete from config where cat='queueworkers' and k='%s'",
- 'workerstarted_'.$k[1]);
- q("update config set k='%s' where cat='queuework' and k='%s'",
- dbesc(uniqid('workitem:',true)),
- 'workitem_'.$k[1]);
- unset($workers[$idx]);
- }
- }
- if (count($workers) > $maxworkers) {
- return false;
- }
- }
- return uniqid('',true);
-
- }
-
- static public function Process() {
-
- self::$queueworker = self::GetWorkerID();
-
- if (!self::$queueworker) {
- logger('Master: unable to obtain worker ID.');
- killme();
- }
-
- set_config('queueworkers','workerstarted_'.self::$queueworker,time());
-
- $workersleep = get_config('system','queue_worker_sleep');
- $workersleep = ($workersleep) ? $workersleep : 5;
- cli_startup();
-
- $work = q("update config set k='%s' where cat='queuework' and k like '%s' limit 1",
- 'workitem_'.self::$queueworker,
- dbesc('workitem:%'));
- $jobs = 0;
- while ($work) {
- $workitem = q("select * from config where cat='queuework' and k='%s'",
- 'workitem_'.self::$queueworker);
-
- if (isset($workitem[0])) {
- $jobs++;
- $workinfo = unserialize($workitem[0]['v']);
- $argc = $workinfo['argc'];
- $argv = $workinfo['argv'];
- logger('Master: process: ' . print_r($argv,true), LOGGER_ALL,LOG_DEBUG);
-
- //Delete unclaimed duplicate workitems.
- q("delete from config where cat='queuework' and k='workitem' and v='%s'",
- serialize($argv));
-
- $cls = '\\Zotlabs\\Daemon\\' . $argv[0];
- $cls::run($argc,$argv);
+ $hookinfo = [
+ 'argv'=>$argv
+ ];
- //Right now we assume that if we get a return, everything is OK.
- //At some point we may want to test whether the run returns true/false
- // and requeue the work to be tried again. But we probably want
- // to implement some sort of "retry interval" first.
+ call_hooks ('daemon_master_release',$hookinfo);
- q("delete from config where cat='queuework' and k='%s'",
- 'workitem_'.self::$queueworker);
- } else {
- break;
- }
- sleep ($workersleep);
- $work = q("update config set k='%s' where cat='queuework' and k like '%s' limit 1",
- 'workitem_'.self::$queueworker,
- dbesc('workitem:%'));
+ $argv = $hookinfo['argv'];
+ $argc = count($argv);
+ if ((!is_array($argv) || (count($argv) < 1))) {
+ return;
}
- logger('Master: Worker Thread: queue items processed:' . $jobs);
- q("delete from config where cat='queueworkers' and k='%s'",
- 'workerstarted_'.self::$queueworker);
- }
- static public function ClearQueue() {
- $work = q("select * from config where cat='queuework' and k like '%s'",
- dbesc('workitem%'));
- foreach ($work as $workitem) {
- $workinfo = unserialize($workitem['v']);
- $argc = $workinfo['argc'];
- $argv = $workinfo['argv'];
- logger('Master: process: ' . print_r($argv,true), LOGGER_ALL,LOG_DEBUG);
- $cls = '\\Zotlabs\\Daemon\\' . $argv[0];
- $cls::run($argc,$argv);
- }
- $work = q("delete from config where cat='queuework' and k like '%s'",
- dbesc('workitem%'));
+ logger('Master: release: ' . json_encode($argv), LOGGER_ALL,LOG_DEBUG);
+ $cls = '\\Zotlabs\\Daemon\\' . $argv[0];
+ $cls::run($argc,$argv);
}
-
}
diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php
index 8cf62c01a..de7439ed7 100644
--- a/Zotlabs/Lib/Apps.php
+++ b/Zotlabs/Lib/Apps.php
@@ -57,7 +57,7 @@ class Apps {
}
static public function get_base_apps() {
- return get_config('system','base_apps',[
+ $x = get_config('system','base_apps',[
'Connections',
'Network',
'Settings',
@@ -72,6 +72,8 @@ class Apps {
'Mail',
'Profile Photo'
]);
+ call_hooks('get_base_apps',$x);
+ return $x;
}
static public function import_system_apps() {
diff --git a/Zotlabs/Lib/PConfig.php b/Zotlabs/Lib/PConfig.php
index 5e5954c95..69f4de2db 100644
--- a/Zotlabs/Lib/PConfig.php
+++ b/Zotlabs/Lib/PConfig.php
@@ -131,14 +131,19 @@ class PConfig {
$dbvalue = ((is_array($value)) ? serialize($value) : $value);
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
+ $now = datetime_convert();
if (! $updated) {
- $updated = datetime_convert();
+ //Sometimes things happen fast... very fast.
+ //To make sure legitimate updates aren't rejected
+ //because not enough time has passed. We say our updates
+ //happened just a short time in the past rather than right now.
+ $updated = datetime_convert('UTC','UTC','-2 seconds');
}
$hash = hash('sha256',$family.':'.$key);
if (self::Get($uid, 'hz_delpconfig', $hash) !== false) {
- if (self::Get($uid, 'hz_delpconfig', $hash) > $updated) {
+ if (self::Get($uid, 'hz_delpconfig', $hash) > $now) {
logger('Refusing to update pconfig with outdated info (Item deleted more recently).', LOGGER_NORMAL, LOG_ERR);
return self::Get($uid,$family,$key);
} else {
@@ -173,7 +178,7 @@ class PConfig {
}
else {
- $new = (\App::$config[$uid][$family]['pcfgud:'.$key] < $updated);
+ $new = (\App::$config[$uid][$family]['pcfgud:'.$key] < $now);
if ($new) {
@@ -241,9 +246,9 @@ class PConfig {
if(is_null($uid) || $uid === false)
return false;
- $updated = ($updated) ? $updated : datetime_convert();
-
- $newer = (\App::$config[$uid][$family]['pcfgud:'.$key] < $updated);
+ $updated = ($updated) ? $updated : datetime_convert('UTC','UTC','-2 seconds');
+ $now = datetime_convert();
+ $newer = (\App::$config[$uid][$family]['pcfgud:'.$key] < $now);
if (! $newer) {
logger('Refusing to delete pconfig with outdated delete request.', LOGGER_NORMAL, LOG_ERR);
diff --git a/doc/hook/daemon_master_release.bb b/doc/hook/daemon_master_release.bb
new file mode 100644
index 000000000..a17216d48
--- /dev/null
+++ b/doc/hook/daemon_master_release.bb
@@ -0,0 +1,5 @@
+[h2]daemon_master_release[/h2]
+
+Permit filtering or alternate methods of processing of background processes when [code] \Zotlabs\Daemon\Master::Release() [/code] is called.
+
+Default behavior is for a new PHP process to fire immediately upon a call to Master::Summon(). This hook permits pre-emption and the ability to provide queuing or other alternatives to this procedure.
diff --git a/doc/hooklist.bb b/doc/hooklist.bb
index 08fc587e2..afb2cebee 100644
--- a/doc/hooklist.bb
+++ b/doc/hooklist.bb
@@ -190,6 +190,9 @@ Hooks allow plugins/addons to "hook into" the code at many points and alter the
[zrl=[baseurl]/help/hook/daemon_addon]daemon_addon[/zrl]
Called when invoking the extensible background daemon
+[zrl=[baseurl]/help/hook/daemon_master_release]daemon_master_release[/zrl]
+ Called at the start of processing \Zotlabs\Daemon\Master::Release()
+
[zrl=[baseurl]/help/hook/directory_item]directory_item[/zrl]
Called when generating a directory listing for display