ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BasicTaskManager.php
Go to the documentation of this file.
1<?php
2
20
35
47abstract class BasicTaskManager implements TaskManager
48{
49 public function __construct(protected Persistence $persistence)
50 {
51 }
52
56 public function executeTask(Task $task, Observer $observer): Value
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 ($value instanceof ThunkValue) {
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 ($task instanceof Job) {
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 ($task instanceof UserInteraction) {
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
113 public function continueTask(Bucket $bucket, Option $option): void
114 {
115 // We do the user interaction
116 $bucket->userInteraction($option);
117 if ($bucket->getState() != State::FINISHED) { // The job is not done after the user interaction, so we continue to run it.
118 $this->run($bucket);
119 } else {
120 $this->persistence->deleteBucket($bucket);
121 }
122 }
123
127 public function quitBucket(Bucket $bucket): void
128 {
129 $this->persistence->deleteBucket($bucket);
130 }
131}
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: Option.php:19
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Job.php:19