From e1dc0d3c99217504de2ac8467156274786efc0bd Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 9 Oct 2014 16:01:11 +0200 Subject: Big load of changes - Added callback functionality for taskmanager tasks. You can launch a task and define a callback function to be run when the task finished. This requires activating the cronjob - Added cron functionality: Add cronjob that calls the cron api every 5 minutes to use it. (See cron.inc.php) - Added eventlog - Added missing translations - Merged main-menu-login and main-menu-logout --- inc/taskmanager.inc.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'inc/taskmanager.inc.php') diff --git a/inc/taskmanager.inc.php b/inc/taskmanager.inc.php index 5813164a..528b3f78 100644 --- a/inc/taskmanager.inc.php +++ b/inc/taskmanager.inc.php @@ -28,7 +28,7 @@ class Taskmanager * @param string $task name of task to start * @param array $data data to pass to the task. the structure depends on the task. * @param boolean $async if true, the function will not wait for the reply of the taskmanager, which means - * the return value is just true (and you won't know if the task could acutally be started) + * the return value is just true (and you won't know if the task could acutally be started) * @return array struct representing the task status, or result of submit, false on communication error */ public static function submit($task, $data = false, $async = false) @@ -49,8 +49,7 @@ class Taskmanager if ($async) return true; $reply = self::readReply($seq); - if ($reply === false || !is_array($reply) || !isset($reply['id']) - || (isset($reply['statusCode']) && $reply['statusCode'] === NO_SUCH_TASK)) { + if ($reply === false || !is_array($reply) || !isset($reply['id']) || (isset($reply['statusCode']) && $reply['statusCode'] === NO_SUCH_TASK)) { self::addErrorMessage($reply); return false; } @@ -117,7 +116,7 @@ class Taskmanager /** * Check whether the given task can be considered failed. * - * @param mixed $task task id or struct representing task + * @param array $task struct representing task, obtained by ::status * @return boolean true if task failed, false if finished successfully or still waiting/running */ public static function isFailed($task) @@ -129,6 +128,22 @@ class Taskmanager return false; } + /** + * Check whether the given task is finished, i.e. either failed or succeeded, + * but is not running, still waiting for execution or simply unknown. + * + * @param array $task struct representing task, obtained by ::status + * @return boolean true if task failed or finished, false if waiting for execution or currently executing, no valid task, etc. + */ + public static function isFinished($task) + { + if (!is_array($task) || !isset($task['statusCode']) || !isset($task['id'])) + return false; + if ($task['statusCode'] === TASK_ERROR || $task['statusCode'] === TASK_FINISHED) + return true; + return false; + } + public static function addErrorMessage($task) { static $failure = false; -- cgit v1.2.3-55-g7522