ILIAS  release_8 Revision v8.24
BasicTaskManager.php
Go to the documentation of this file.
1<?php
2
20
33
45abstract class BasicTaskManager implements TaskManager
46{
48
50 {
51 $this->persistence = $persistence;
52 }
53
57 public function executeTask(Task $task, Observer $observer): Value
58 {
59 $observer->notifyState(State::RUNNING);
61 $values = $task->getInput();
62 $final_values = [];
63 $replace_thunk_values = false;
64 foreach ($values as $value) {
65 if (is_a($value, ThunkValue::class)) {
66 $value = $this->executeTask($value->getParentTask(), $observer);
67 $replace_thunk_values = true;
68 }
69 $final_values[] = $value;
70 }
71
72 if ($replace_thunk_values) {
73 $task->setInput($final_values);
74 }
75
76 if (is_a($task, Task\Job::class)) {
78 $job = $task;
79 $observer->notifyCurrentTask($job);
80 $value = $job->run($final_values, $observer);
81 if (!$value->getType()->isExtensionOf($job->getOutputType())) {
82 throw new Exception("The job " . $job->getType()
83 . " did state to output a value of type "
84 . $job->getOutputType() . " but outputted a value of type "
85 . $value->getType());
86 }
87 $observer->notifyPercentage($job, 100);
88
89 return $value;
90 }
91
92 if (is_a($task, Task\UserInteraction::class)) {
94 $user_interaction = $task;
95
96 if ($user_interaction->canBeSkipped($final_values)) {
97 if ($task->isFinal()) {
98 throw new UserInteractionSkippedException('Final interaction skipped');
99 }
100 return $task->getSkippedValue($task->getInput());
101 }
102
103 $observer->notifyCurrentTask($user_interaction);
105 throw new UserInteractionRequiredException("User interaction required.");
106 }
107
108 throw new Exception("You need to execute a Job or a UserInteraction.");
109 }
110
114 public function continueTask(Bucket $bucket, Option $option): void
115 {
116 // We do the user interaction
117 $bucket->userInteraction($option);
118 if ($bucket->getState() != State::FINISHED) { // The job is not done after the user interaction, so we continue to run it.
119 $this->run($bucket);
120 } else {
121 $this->persistence->deleteBucket($bucket);
122 }
123 }
124
128 public function quitBucket(Bucket $bucket): void
129 {
130 $this->persistence->deleteBucket($bucket);
131 }
132}
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, int $percentage)
You can change the progress of a currently running task.
notifyCurrentTask(Task $task)
If the current task changes notify the observer.
notifyState(int $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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Job.php:19