Split cronhook call to several single calls
This commit is contained in:
parent
c6f7952f37
commit
b9dbb0ace1
|
@ -142,28 +142,44 @@ function cron_run(&$argv, &$argc){
|
|||
// Repair entries in the 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;
|
||||
$generation = 0;
|
||||
$force = false;
|
||||
$restart = false;
|
||||
|
||||
if(($argc > 1) && ($argv[1] == 'force'))
|
||||
if (($argc > 1) && ($argv[1] == 'force'))
|
||||
$force = true;
|
||||
|
||||
if(($argc > 1) && ($argv[1] == 'restart')) {
|
||||
if (($argc > 1) && ($argv[1] == 'restart')) {
|
||||
$restart = true;
|
||||
$generation = intval($argv[2]);
|
||||
if(! $generation)
|
||||
if (!$generation)
|
||||
killme();
|
||||
}
|
||||
|
||||
if(($argc > 1) && intval($argv[1])) {
|
||||
if (($argc > 1) && intval($argv[1])) {
|
||||
$manual_id = intval($argv[1]);
|
||||
$force = true;
|
||||
}
|
||||
|
||||
$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')));
|
||||
|
||||
// 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)
|
||||
);
|
||||
|
||||
if(! count($contacts)) {
|
||||
if (!count($contacts)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($contacts as $c) {
|
||||
foreach ($contacts as $c) {
|
||||
|
||||
$res = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
|
||||
intval($c['id'])
|
||||
|
@ -266,7 +282,7 @@ function cron_run(&$argv, &$argc){
|
|||
$update = true;
|
||||
break;
|
||||
}
|
||||
if(!$update)
|
||||
if (!$update)
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -278,12 +294,6 @@ function cron_run(&$argv, &$argc){
|
|||
@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;
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
$poll_interval = intval(get_config('system','cronhook_interval'));
|
||||
|
@ -47,13 +58,17 @@ function cronhooks_run(&$argv, &$argc){
|
|||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
load_hooks();
|
||||
|
||||
logger('cronhooks: start');
|
||||
|
||||
$d = datetime_convert();
|
||||
|
||||
call_hooks('cron', $d);
|
||||
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);
|
||||
|
||||
logger('cronhooks: end');
|
||||
|
||||
|
|
|
@ -205,37 +205,41 @@ function load_hooks() {
|
|||
* @param string $name of the hook to call
|
||||
* @param string|array &$data to transmit to the callback handler
|
||||
*/
|
||||
if(! function_exists('call_hooks')) {
|
||||
function call_hooks($name, &$data = null) {
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
$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) {
|
||||
// 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)
|
||||
continue;
|
||||
/**
|
||||
* @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
|
||||
if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/'.current_theme()) === false)
|
||||
return;
|
||||
|
||||
@include_once($hook[0]);
|
||||
if(function_exists($hook[1])) {
|
||||
$func = $hook[1];
|
||||
//logger($name." => ".$hook[0].":".$func."()", LOGGER_DEBUG);
|
||||
$func($a,$data);
|
||||
}
|
||||
else {
|
||||
// remove orphan hooks
|
||||
q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s'",
|
||||
dbesc($name),
|
||||
dbesc($hook[0]),
|
||||
dbesc($hook[1])
|
||||
);
|
||||
}
|
||||
}
|
||||
@include_once($hook[0]);
|
||||
if (function_exists($hook[1])) {
|
||||
$func = $hook[1];
|
||||
$func($a, $data);
|
||||
} else {
|
||||
// remove orphan hooks
|
||||
q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s'",
|
||||
dbesc($name),
|
||||
dbesc($hook[0]),
|
||||
dbesc($hook[1])
|
||||
);
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
//check if an app_menu hook exist for plugin $name.
|
||||
//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")) {
|
||||
// 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
|
||||
proc_run("php","include/cronhooks.php");
|
||||
proc_run(PRIORITY_MEDIUM, "include/cronhooks.php");
|
||||
|
||||
// Cleaning dead processes
|
||||
poller_kill_stale_workers();
|
||||
|
|
Loading…
Reference in a new issue