mirror of
https://github.com/friendica/friendica
synced 2025-05-05 21:44:11 +02:00
Hook calls can now be forked into a worker queue entry
This commit is contained in:
parent
66e3c1836e
commit
47d165cb25
9 changed files with 47 additions and 68 deletions
|
@ -40,6 +40,9 @@ Class Cron {
|
|||
|
||||
logger('cron: start');
|
||||
|
||||
// Fork the cron jobs in separate parts to avoid problems when one of them is crashing
|
||||
Addon::ForkHooks($a->queue['priority'], "cron");
|
||||
|
||||
// run queue delivery process in the background
|
||||
Worker::add(PRIORITY_NEGLIGIBLE, "Queue");
|
||||
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @file src/Worker/CronHooks.php
|
||||
*/
|
||||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
Class CronHooks {
|
||||
public static function execute($hook = '') {
|
||||
global $a;
|
||||
|
||||
if (($hook != '') && is_array($a->hooks) && array_key_exists("cron", $a->hooks)) {
|
||||
foreach ($a->hooks["cron"] as $single_hook) {
|
||||
if ($single_hook[1] == $hook) {
|
||||
logger("Calling cron hook '" . $hook . "'", LOGGER_DEBUG);
|
||||
Addon::callSingleHook($a, $hook, $single_hook);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$last = Config::get('system', 'last_cronhook');
|
||||
|
||||
$poll_interval = intval(Config::get('system', 'cronhook_interval'));
|
||||
if (!$poll_interval) {
|
||||
$poll_interval = 9;
|
||||
}
|
||||
|
||||
if ($last) {
|
||||
$next = $last + ($poll_interval * 60);
|
||||
if ($next > time()) {
|
||||
logger('cronhook intervall not reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$a->set_baseurl(Config::get('system', 'url'));
|
||||
|
||||
logger('cronhooks: start');
|
||||
|
||||
$d = DateTimeFormat::utcNow();
|
||||
|
||||
if (is_array($a->hooks) && array_key_exists("cron", $a->hooks)) {
|
||||
foreach ($a->hooks["cron"] as $hook) {
|
||||
logger("Calling cronhooks for '" . $hook[1] . "'", LOGGER_DEBUG);
|
||||
Worker::add(PRIORITY_MEDIUM, "CronHooks", $hook[1]);
|
||||
}
|
||||
}
|
||||
|
||||
logger('cronhooks: end');
|
||||
|
||||
Config::set('system', 'last_cronhook', time());
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
19
src/Worker/ForkHook.php
Normal file
19
src/Worker/ForkHook.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* @file src/Worker/ForkHook.php
|
||||
*/
|
||||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Addon;
|
||||
|
||||
Class ForkHook {
|
||||
public static function execute($name, $hook_json, $data_json) {
|
||||
global $a;
|
||||
|
||||
$hook = json_decode($hook_json, true);
|
||||
$data = json_decode($data_json, true);
|
||||
|
||||
Addon::callSingleHook($a, $name, $hook, $data);
|
||||
}
|
||||
}
|
|
@ -553,7 +553,8 @@ class Notifier {
|
|||
logger('notifier: calling hooks', LOGGER_DEBUG);
|
||||
|
||||
if ($normal_mode) {
|
||||
Addon::callHooks('notifier_normal',$target_item);
|
||||
Addon::ForkHooks($a->queue['priority'], 'notifier_normal', $target_item);
|
||||
//Addon::callHooks('notifier_normal',$target_item);
|
||||
}
|
||||
|
||||
Addon::callHooks('notifier_end',$target_item);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue