ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $user_interaction = $task;
94
95 if ($user_interaction->canBeSkipped($final_values)) {
96 if ($task->isFinal()) {
97 throw new UserInteractionSkippedException('Final interaction skipped');
98 }
99 return $task->getSkippedValue($task->getInput());
100 }
101
102 $observer->notifyCurrentTask($user_interaction);
104 throw new UserInteractionRequiredException("User interaction required.");
105 }
106
107 throw new Exception("You need to execute a Job or a UserInteraction.");
108 }
109
110
119 public function continueTask(Bucket $bucket, Option $option)
120 {
121 // We do the user interaction
122 $bucket->userInteraction($option);
123 if ($bucket->getState() != State::FINISHED) { // The job is not done after the user interaction, so we continue to run it.
124 $this->run($bucket);
125 } else {
126 $this->persistence->deleteBucket($bucket);
127 }
128 }
129
130
134 public function quitBucket(Bucket $bucket)
135 {
136 $this->persistence->deleteBucket($bucket);
137 }
138}
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.