Split cronhook call to several single calls
This commit is contained in:
parent
c6f7952f37
commit
b9dbb0ace1
4 changed files with 71 additions and 42 deletions
|
@ -142,28 +142,44 @@ function cron_run(&$argv, &$argc){
|
||||||
// Repair entries in the database
|
// Repair entries in the database
|
||||||
cron_repair_database();
|
cron_repair_database();
|
||||||
|
|
||||||
|
// Poll contacts
|
||||||
|
cron_poll_contacts($argc, $argv);
|
||||||
|
|
||||||
|
logger('cron: end');
|
||||||
|
|
||||||
|
set_config('system','last_cron', time());
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clear cache entries
|
||||||
|
*
|
||||||
|
* @param App $a
|
||||||
|
*/
|
||||||
|
function cron_poll_contacts($argc, $argv) {
|
||||||
$manual_id = 0;
|
$manual_id = 0;
|
||||||
$generation = 0;
|
$generation = 0;
|
||||||
$force = false;
|
$force = false;
|
||||||
$restart = false;
|
$restart = false;
|
||||||
|
|
||||||
if(($argc > 1) && ($argv[1] == 'force'))
|
if (($argc > 1) && ($argv[1] == 'force'))
|
||||||
$force = true;
|
$force = true;
|
||||||
|
|
||||||
if(($argc > 1) && ($argv[1] == 'restart')) {
|
if (($argc > 1) && ($argv[1] == 'restart')) {
|
||||||
$restart = true;
|
$restart = true;
|
||||||
$generation = intval($argv[2]);
|
$generation = intval($argv[2]);
|
||||||
if(! $generation)
|
if (!$generation)
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($argc > 1) && intval($argv[1])) {
|
if (($argc > 1) && intval($argv[1])) {
|
||||||
$manual_id = intval($argv[1]);
|
$manual_id = intval($argv[1]);
|
||||||
$force = true;
|
$force = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$interval = intval(get_config('system','poll_interval'));
|
$interval = intval(get_config('system','poll_interval'));
|
||||||
if(! $interval)
|
if (!$interval)
|
||||||
$interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval')));
|
$interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval')));
|
||||||
|
|
||||||
// If we are using the worker we don't need a delivery interval
|
// If we are using the worker we don't need a delivery interval
|
||||||
|
@ -200,11 +216,11 @@ function cron_run(&$argv, &$argc){
|
||||||
dbesc(NETWORK_MAIL2)
|
dbesc(NETWORK_MAIL2)
|
||||||
);
|
);
|
||||||
|
|
||||||
if(! count($contacts)) {
|
if (!count($contacts)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($contacts as $c) {
|
foreach ($contacts as $c) {
|
||||||
|
|
||||||
$res = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
|
$res = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
|
||||||
intval($c['id'])
|
intval($c['id'])
|
||||||
|
@ -266,7 +282,7 @@ function cron_run(&$argv, &$argc){
|
||||||
$update = true;
|
$update = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(!$update)
|
if (!$update)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,12 +294,6 @@ function cron_run(&$argv, &$argc){
|
||||||
@time_sleep_until(microtime(true) + (float) $interval);
|
@time_sleep_until(microtime(true) + (float) $interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger('cron: end');
|
|
||||||
|
|
||||||
set_config('system','last_cron', time());
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,6 +31,17 @@ function cronhooks_run(&$argv, &$argc){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
load_hooks();
|
||||||
|
|
||||||
|
if (($argc == 2) AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
|
||||||
|
foreach ($a->hooks["cron"] as $hook)
|
||||||
|
if ($hook[1] == $argv[1]) {
|
||||||
|
logger("Calling cron hook '".$hook[1]."'", LOGGER_DEBUG);
|
||||||
|
call_single_hook($a, $name, $hook, $data);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$last = get_config('system','last_cronhook');
|
$last = get_config('system','last_cronhook');
|
||||||
|
|
||||||
$poll_interval = intval(get_config('system','cronhook_interval'));
|
$poll_interval = intval(get_config('system','cronhook_interval'));
|
||||||
|
@ -47,12 +58,16 @@ function cronhooks_run(&$argv, &$argc){
|
||||||
|
|
||||||
$a->set_baseurl(get_config('system','url'));
|
$a->set_baseurl(get_config('system','url'));
|
||||||
|
|
||||||
load_hooks();
|
|
||||||
|
|
||||||
logger('cronhooks: start');
|
logger('cronhooks: start');
|
||||||
|
|
||||||
$d = datetime_convert();
|
$d = datetime_convert();
|
||||||
|
|
||||||
|
if (get_config("system", "worker") AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
|
||||||
|
foreach ($a->hooks["cron"] as $hook) {
|
||||||
|
logger("Calling cronhooks for '".$hook[1]."'", LOGGER_DEBUG);
|
||||||
|
proc_run(PRIORITY_MEDIUM, "include/cronhooks.php", $hook[1]);
|
||||||
|
}
|
||||||
|
} else
|
||||||
call_hooks('cron', $d);
|
call_hooks('cron', $d);
|
||||||
|
|
||||||
logger('cronhooks: end');
|
logger('cronhooks: end');
|
||||||
|
|
|
@ -205,27 +205,33 @@ function load_hooks() {
|
||||||
* @param string $name of the hook to call
|
* @param string $name of the hook to call
|
||||||
* @param string|array &$data to transmit to the callback handler
|
* @param string|array &$data to transmit to the callback handler
|
||||||
*/
|
*/
|
||||||
if(! function_exists('call_hooks')) {
|
|
||||||
function call_hooks($name, &$data = null) {
|
function call_hooks($name, &$data = null) {
|
||||||
$stamp1 = microtime(true);
|
$stamp1 = microtime(true);
|
||||||
|
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
|
|
||||||
#logger($name, LOGGER_ALL);
|
if (is_array($a->hooks) && array_key_exists($name, $a->hooks))
|
||||||
|
foreach ($a->hooks[$name] as $hook)
|
||||||
|
call_single_hook($a, $name, $hook, $data);
|
||||||
|
}
|
||||||
|
|
||||||
if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) {
|
/**
|
||||||
foreach($a->hooks[$name] as $hook) {
|
* @brief Calls a single hook.
|
||||||
|
*
|
||||||
|
* @param string $name of the hook to call
|
||||||
|
* @param array $hook Hook data
|
||||||
|
* @param string|array &$data to transmit to the callback handler
|
||||||
|
*/
|
||||||
|
function call_single_hook($a, $name, $hook, &$data = null) {
|
||||||
// Don't run a theme's hook if the user isn't using the theme
|
// Don't run a theme's hook if the user isn't using the theme
|
||||||
if(strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/'.current_theme()) === false)
|
if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/'.current_theme()) === false)
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
@include_once($hook[0]);
|
@include_once($hook[0]);
|
||||||
if(function_exists($hook[1])) {
|
if (function_exists($hook[1])) {
|
||||||
$func = $hook[1];
|
$func = $hook[1];
|
||||||
//logger($name." => ".$hook[0].":".$func."()", LOGGER_DEBUG);
|
$func($a, $data);
|
||||||
$func($a,$data);
|
} else {
|
||||||
}
|
|
||||||
else {
|
|
||||||
// remove orphan hooks
|
// remove orphan hooks
|
||||||
q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s'",
|
q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s'",
|
||||||
dbesc($name),
|
dbesc($name),
|
||||||
|
@ -233,9 +239,7 @@ function call_hooks($name, &$data = null) {
|
||||||
dbesc($hook[1])
|
dbesc($hook[1])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}}
|
|
||||||
|
|
||||||
//check if an app_menu hook exist for plugin $name.
|
//check if an app_menu hook exist for plugin $name.
|
||||||
//Return true if the plugin is an app
|
//Return true if the plugin is an app
|
||||||
|
|
|
@ -46,10 +46,10 @@ function poller_run(&$argv, &$argc){
|
||||||
|
|
||||||
if(($argc <= 1) OR ($argv[1] != "no_cron")) {
|
if(($argc <= 1) OR ($argv[1] != "no_cron")) {
|
||||||
// Run the cron job that calls all other jobs
|
// Run the cron job that calls all other jobs
|
||||||
proc_run("php","include/cron.php");
|
proc_run(PRIORITY_MEDIUM, "include/cron.php");
|
||||||
|
|
||||||
// Run the cronhooks job separately from cron for being able to use a different timing
|
// Run the cronhooks job separately from cron for being able to use a different timing
|
||||||
proc_run("php","include/cronhooks.php");
|
proc_run(PRIORITY_MEDIUM, "include/cronhooks.php");
|
||||||
|
|
||||||
// Cleaning dead processes
|
// Cleaning dead processes
|
||||||
poller_kill_stale_workers();
|
poller_kill_stale_workers();
|
||||||
|
|
Loading…
Reference in a new issue