define('FRIENDICA_CODENAME', 'Asparagus');
define('FRIENDICA_VERSION', '3.6-dev');
define('DFRN_PROTOCOL_VERSION', '2.23');
-define('DB_UPDATE_VERSION', 1248);
+define('DB_UPDATE_VERSION', 1249);
define('NEW_UPDATE_ROUTINE_VERSION', 1170);
/**
--
CREATE TABLE IF NOT EXISTS `workerqueue` (
`id` int NOT NULL auto_increment COMMENT 'Auto incremented worker task id',
- `parameter` text COMMENT 'Task command',
+ `parameter` mediumtext COMMENT 'Task command',
`priority` tinyint NOT NULL DEFAULT 0 COMMENT 'Task priority',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date',
`pid` int NOT NULL DEFAULT 0 COMMENT 'Process id of the worker',
use Friendica\Core\Config;
use Friendica\Database\DBM;
+use Friendica\Core\Worker;
use dba;
dba::close($r);
}
+ /**
+ * @brief Forks a hook.
+ *
+ * Use this function when you want to fork a hook via the worker.
+ *
+ * @param string $name of the hook to call
+ * @param string|array $data to transmit to the callback handler
+ */
+ public static function ForkHooks($priority, $name, $data = null)
+ {
+ $a = get_app();
+
+ if (is_array($a->hooks) && array_key_exists($name, $a->hooks)) {
+ foreach ($a->hooks[$name] as $hook) {
+ Worker::add($priority, 'ForkHook', $name, json_encode($hook), json_encode($data));
+ }
+ }
+ }
+
/**
* @brief Calls a hook.
*
// Run the cron job that calls all other jobs
self::add(PRIORITY_MEDIUM, "Cron");
- // Run the cronhooks job separately from cron for being able to use a different timing
- self::add(PRIORITY_MEDIUM, "CronHooks");
-
// Cleaning dead processes
self::killStaleWorkers();
}
"comment" => "Background tasks queue entries",
"fields" => [
"id" => ["type" => "int", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "Auto incremented worker task id"],
- "parameter" => ["type" => "text", "comment" => "Task command"],
+ "parameter" => ["type" => "mediumtext", "comment" => "Task command"],
"priority" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Task priority"],
"created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Creation date"],
"pid" => ["type" => "int", "not null" => "1", "default" => "0", "comment" => "Process id of the worker"],
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");
+++ /dev/null
-<?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;
- }
-}
--- /dev/null
+<?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);
+ }
+}
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);