ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
BasicTaskManager.php
Go to the documentation of this file.
1<?php
2
4
17
34abstract class BasicTaskManager implements TaskManager
35{
36
40 protected $persistence;
41
42
44 {
45 $this->persistence = $persistence;
46 }
47
48
56 public function executeTask(Task $task, Observer $observer)
57 {
58 $observer->notifyState(State::RUNNING);
60 $values = $task->getInput();
61 $final_values = [];
62 $replace_thunk_values = false;
63 foreach ($values as $value) {
64 if (is_a($value, ThunkValue::class)) {
65 $value = $this->executeTask($value->getParentTask(), $observer);
66 $replace_thunk_values = true;
67 }
68 $final_values[] = $value;
69 }
70
71 if ($replace_thunk_values) {
72 $task->setInput($final_values);
73 }
74
75 if (is_a($task, Task\Job::class)) {
77 $job = $task;
78 $observer->notifyCurrentTask($job);
79 $value = $job->run($final_values, $observer);
80 if (!$value->getType()->isExtensionOf($job->getOutputType())) {
81 throw new Exception("The job " . $job->getType()
82 . " did state to output a value of type "
83 . $job->getOutputType() . " but outputted a value of type "
84 . $value->getType());
85 }
86 $observer->notifyPercentage($job, 100);
87
88 return $value;
89 }
90
91 if (is_a($task, Task\UserInteraction::class)) {
93 $userInteraction = $task;
94
95 if ($userInteraction->canBeSkipped($final_values)) {
96 $observer->notifyState(State::FINISHED);
97 throw new UserInteractionSkippedException("User interaction skipped.");
98 } else {
99 $observer->notifyCurrentTask($userInteraction);
101 throw new UserInteractionRequiredException("User interaction required.");
102 }
103 }
104
105 throw new Exception("You need to execute a Job or a UserInteraction.");
106 }
107
108
117 public function continueTask(Bucket $bucket, Option $option)
118 {
119 // We do the user interaction
120 $bucket->userInteraction($option);
121 if ($bucket->getState() != State::FINISHED) { // The job is not done after the user interaction, so we continue to run it.
122 $this->run($bucket);
123 } else {
124 $this->persistence->deleteBucket($bucket);
125 }
126 }
127
128
132 public function quitBucket(Bucket $bucket)
133 {
134 $this->persistence->deleteBucket($bucket);
135 }
136}
An exception for terminatinating execution or to throw for unit testing.
quitBucket(Bucket $bucket)
Quits and deletes a Bucket with all it's Jobs.
continueTask(Bucket $bucket, Option $option)
Continue a task with a given option.
userInteraction(Option $option)
Let the user interact with the bucket task queue.
notifyPercentage(Task $task, $percentage)
You can change the progress of a currently running task.
notifyCurrentTask(Task $task)
If the current task changes notify the observer.
notifyState($state)
If the bucket goes into another state notify the observer.
executeTask(Task $task, Observer $observer)
Actually executes a task.
run(Bucket $bucket)
Depending on your background task settings, executes or puts the task into the queue.
$values