Some clean up for the worker, arrays are now supported as parameter
This commit is contained in:
parent
2dadbf3f72
commit
2a762868e9
2
boot.php
2
boot.php
|
@ -39,7 +39,7 @@ define('FRIENDICA_PLATFORM', 'Friendica');
|
||||||
define('FRIENDICA_CODENAME', 'Asparagus');
|
define('FRIENDICA_CODENAME', 'Asparagus');
|
||||||
define('FRIENDICA_VERSION', '3.6-dev');
|
define('FRIENDICA_VERSION', '3.6-dev');
|
||||||
define('DFRN_PROTOCOL_VERSION', '2.23');
|
define('DFRN_PROTOCOL_VERSION', '2.23');
|
||||||
define('DB_UPDATE_VERSION', 1252);
|
define('DB_UPDATE_VERSION', 1253);
|
||||||
define('NEW_UPDATE_ROUTINE_VERSION', 1170);
|
define('NEW_UPDATE_ROUTINE_VERSION', 1170);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
-- Friendica 3.6-dev (Asparagus)
|
-- Friendica 3.6-dev (Asparagus)
|
||||||
-- DB_UPDATE_VERSION 1250
|
-- DB_UPDATE_VERSION 1253
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
@ -1003,6 +1003,7 @@ CREATE TABLE IF NOT EXISTS `tokens` (
|
||||||
--
|
--
|
||||||
CREATE TABLE IF NOT EXISTS `user` (
|
CREATE TABLE IF NOT EXISTS `user` (
|
||||||
`uid` mediumint NOT NULL auto_increment COMMENT '',
|
`uid` mediumint NOT NULL auto_increment COMMENT '',
|
||||||
|
`parent-uid` mediumint NOT NULL DEFAULT 0 COMMENT 'The parent user that has full control about this user',
|
||||||
`guid` varchar(64) NOT NULL DEFAULT '' COMMENT '',
|
`guid` varchar(64) NOT NULL DEFAULT '' COMMENT '',
|
||||||
`username` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
`username` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
||||||
`password` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
`password` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
||||||
|
@ -1065,7 +1066,7 @@ CREATE TABLE IF NOT EXISTS `userd` (
|
||||||
--
|
--
|
||||||
CREATE TABLE IF NOT EXISTS `workerqueue` (
|
CREATE TABLE IF NOT EXISTS `workerqueue` (
|
||||||
`id` int NOT NULL auto_increment COMMENT 'Auto incremented worker task id',
|
`id` int NOT NULL auto_increment COMMENT 'Auto incremented worker task id',
|
||||||
`parameter` mediumtext COMMENT 'Task command',
|
`parameter` mediumblob COMMENT 'Task command',
|
||||||
`priority` tinyint NOT NULL DEFAULT 0 COMMENT 'Task priority',
|
`priority` tinyint NOT NULL DEFAULT 0 COMMENT 'Task priority',
|
||||||
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date',
|
`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',
|
`pid` int NOT NULL DEFAULT 0 COMMENT 'Process id of the worker',
|
||||||
|
|
|
@ -200,7 +200,7 @@ class Addon
|
||||||
|
|
||||||
if (is_array($a->hooks) && array_key_exists($name, $a->hooks)) {
|
if (is_array($a->hooks) && array_key_exists($name, $a->hooks)) {
|
||||||
foreach ($a->hooks[$name] as $hook) {
|
foreach ($a->hooks[$name] as $hook) {
|
||||||
Worker::add($priority, 'ForkHook', $name, json_encode($hook), json_encode($data));
|
Worker::add($priority, 'ForkHook', $name, $hook, $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,7 +218,7 @@ class Worker
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$argv = json_decode($queue["parameter"]);
|
$argv = json_decode($queue["parameter"], true);
|
||||||
|
|
||||||
// Check for existance and validity of the include file
|
// Check for existance and validity of the include file
|
||||||
$include = $argv[0];
|
$include = $argv[0];
|
||||||
|
@ -552,7 +552,7 @@ class Worker
|
||||||
$max_duration_defaults = [PRIORITY_CRITICAL => 720, PRIORITY_HIGH => 10, PRIORITY_MEDIUM => 60, PRIORITY_LOW => 180, PRIORITY_NEGLIGIBLE => 720];
|
$max_duration_defaults = [PRIORITY_CRITICAL => 720, PRIORITY_HIGH => 10, PRIORITY_MEDIUM => 60, PRIORITY_LOW => 180, PRIORITY_NEGLIGIBLE => 720];
|
||||||
$max_duration = $max_duration_defaults[$entry["priority"]];
|
$max_duration = $max_duration_defaults[$entry["priority"]];
|
||||||
|
|
||||||
$argv = json_decode($entry["parameter"]);
|
$argv = json_decode($entry["parameter"], true);
|
||||||
$argv[0] = basename($argv[0]);
|
$argv[0] = basename($argv[0]);
|
||||||
|
|
||||||
// How long is the process already running?
|
// How long is the process already running?
|
||||||
|
@ -1001,32 +1001,12 @@ class Worker
|
||||||
*/
|
*/
|
||||||
public static function add($cmd)
|
public static function add($cmd)
|
||||||
{
|
{
|
||||||
$proc_args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
$args = [];
|
if (!count($args)) {
|
||||||
if (!count($proc_args)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preserve the first parameter
|
|
||||||
// It could contain a command, the priority or an parameter array
|
|
||||||
// If we use the parameter array we have to protect it from the following function
|
|
||||||
$run_parameter = array_shift($proc_args);
|
|
||||||
|
|
||||||
// expand any arrays
|
|
||||||
foreach ($proc_args as $arg) {
|
|
||||||
if (is_array($arg)) {
|
|
||||||
foreach ($arg as $n) {
|
|
||||||
$args[] = $n;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$args[] = $arg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we add the run parameters back to the array
|
|
||||||
array_unshift($args, $run_parameter);
|
|
||||||
|
|
||||||
$arr = ['args' => $args, 'run_cmd' => true];
|
$arr = ['args' => $args, 'run_cmd' => true];
|
||||||
|
|
||||||
Addon::callHooks("proc_run", $arr);
|
Addon::callHooks("proc_run", $arr);
|
||||||
|
@ -1052,10 +1032,9 @@ class Worker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$argv = $args;
|
array_shift($args);
|
||||||
array_shift($argv);
|
|
||||||
|
|
||||||
$parameters = json_encode($argv);
|
$parameters = json_encode($args);
|
||||||
$found = dba::exists('workerqueue', ['parameter' => $parameters, 'done' => false]);
|
$found = dba::exists('workerqueue', ['parameter' => $parameters, 'done' => false]);
|
||||||
|
|
||||||
// Quit if there was a database error - a precaution for the update process to 3.5.3
|
// Quit if there was a database error - a precaution for the update process to 3.5.3
|
||||||
|
|
|
@ -1772,7 +1772,7 @@ class DBStructure
|
||||||
"comment" => "Background tasks queue entries",
|
"comment" => "Background tasks queue entries",
|
||||||
"fields" => [
|
"fields" => [
|
||||||
"id" => ["type" => "int", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "Auto incremented worker task id"],
|
"id" => ["type" => "int", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "Auto incremented worker task id"],
|
||||||
"parameter" => ["type" => "mediumtext", "comment" => "Task command"],
|
"parameter" => ["type" => "mediumblob", "comment" => "Task command"],
|
||||||
"priority" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Task priority"],
|
"priority" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Task priority"],
|
||||||
"created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Creation date"],
|
"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"],
|
"pid" => ["type" => "int", "not null" => "1", "default" => "0", "comment" => "Process id of the worker"],
|
||||||
|
|
|
@ -8,12 +8,9 @@ namespace Friendica\Worker;
|
||||||
use Friendica\Core\Addon;
|
use Friendica\Core\Addon;
|
||||||
|
|
||||||
Class ForkHook {
|
Class ForkHook {
|
||||||
public static function execute($name, $hook_json, $data_json) {
|
public static function execute($name, $hook, $data) {
|
||||||
global $a;
|
global $a;
|
||||||
|
|
||||||
$hook = json_decode($hook_json, true);
|
|
||||||
$data = json_decode($data_json, true);
|
|
||||||
|
|
||||||
Addon::callSingleHook($a, $name, $hook, $data);
|
Addon::callSingleHook($a, $name, $hook, $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue