Merge pull request #4437 from annando/worker-cleanup
Some clean up for the worker, arrays are now supported as parameter
This commit is contained in:
commit
30e8361dcb
6 changed files with 13 additions and 36 deletions
2
boot.php
2
boot.php
|
@ -39,7 +39,7 @@ define('FRIENDICA_PLATFORM', 'Friendica');
|
|||
define('FRIENDICA_CODENAME', 'Asparagus');
|
||||
define('FRIENDICA_VERSION', '3.6-dev');
|
||||
define('DFRN_PROTOCOL_VERSION', '2.23');
|
||||
define('DB_UPDATE_VERSION', 1252);
|
||||
define('DB_UPDATE_VERSION', 1253);
|
||||
define('NEW_UPDATE_ROUTINE_VERSION', 1170);
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- 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` (
|
||||
`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 '',
|
||||
`username` 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` (
|
||||
`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',
|
||||
`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',
|
||||
|
|
|
@ -200,7 +200,7 @@ class Addon
|
|||
|
||||
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));
|
||||
Worker::add($priority, 'ForkHook', $name, $hook, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -218,7 +218,7 @@ class Worker
|
|||
return false;
|
||||
}
|
||||
|
||||
$argv = json_decode($queue["parameter"]);
|
||||
$argv = json_decode($queue["parameter"], true);
|
||||
|
||||
// Check for existance and validity of the include file
|
||||
$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 = $max_duration_defaults[$entry["priority"]];
|
||||
|
||||
$argv = json_decode($entry["parameter"]);
|
||||
$argv = json_decode($entry["parameter"], true);
|
||||
$argv[0] = basename($argv[0]);
|
||||
|
||||
// How long is the process already running?
|
||||
|
@ -1001,32 +1001,12 @@ class Worker
|
|||
*/
|
||||
public static function add($cmd)
|
||||
{
|
||||
$proc_args = func_get_args();
|
||||
$args = func_get_args();
|
||||
|
||||
$args = [];
|
||||
if (!count($proc_args)) {
|
||||
if (!count($args)) {
|
||||
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];
|
||||
|
||||
Addon::callHooks("proc_run", $arr);
|
||||
|
@ -1052,10 +1032,9 @@ class Worker
|
|||
}
|
||||
}
|
||||
|
||||
$argv = $args;
|
||||
array_shift($argv);
|
||||
array_shift($args);
|
||||
|
||||
$parameters = json_encode($argv);
|
||||
$parameters = json_encode($args);
|
||||
$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
|
||||
|
|
|
@ -1772,7 +1772,7 @@ class DBStructure
|
|||
"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" => "mediumtext", "comment" => "Task command"],
|
||||
"parameter" => ["type" => "mediumblob", "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"],
|
||||
|
|
|
@ -8,12 +8,9 @@ namespace Friendica\Worker;
|
|||
use Friendica\Core\Addon;
|
||||
|
||||
Class ForkHook {
|
||||
public static function execute($name, $hook_json, $data_json) {
|
||||
public static function execute($name, $hook, $data) {
|
||||
global $a;
|
||||
|
||||
$hook = json_decode($hook_json, true);
|
||||
$data = json_decode($data_json, true);
|
||||
|
||||
Addon::callSingleHook($a, $name, $hook, $data);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue