summaryrefslogtreecommitdiffstats
path: root/inc/taskmanager.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2014-10-09 16:01:11 +0200
committerSimon Rettberg2014-10-09 16:01:11 +0200
commite1dc0d3c99217504de2ac8467156274786efc0bd (patch)
tree130d7fed1fff8aaaffe5942cf2a3d6bb1dad03c8 /inc/taskmanager.inc.php
parentMinor fixes and improvements (diff)
downloadslx-admin-e1dc0d3c99217504de2ac8467156274786efc0bd.tar.gz
slx-admin-e1dc0d3c99217504de2ac8467156274786efc0bd.tar.xz
slx-admin-e1dc0d3c99217504de2ac8467156274786efc0bd.zip
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
Diffstat (limited to 'inc/taskmanager.inc.php')
-rw-r--r--inc/taskmanager.inc.php23
1 files changed, 19 insertions, 4 deletions
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;