ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket Class Reference
+ Inheritance diagram for ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket:
+ Collaboration diagram for ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket:

Public Member Functions

 getUserId ()
 
 setUserId (int $user_id)
 
 setPercentage (Task $task, int $percentage)
 
 setOverallPercentage (int $percentage)
 
 setCurrentTask (Task $task)
 
 setTask (Task $task)
 
 getOverallPercentage ()
 
 setState (int $state)
 
 getCurrentTask ()
 
 hasCurrentTask ()
 
 getTask ()
 
 getState ()
 
 checkIntegrity ()
 
 userInteraction (Option $option)
 
 getTitle ()
 
 setTitle (string $title)
 
 getDescription ()
 
 setDescription (string $description)
 
 heartbeat ()
 There was something going on in the bucket, it's still working. More...
 
 setLastHeartbeat (int $timestamp)
 
 getLastHeartbeat ()
 When was the last time that something happened on this bucket? More...
 
- Public Member Functions inherited from ILIAS\BackgroundTasks\Bucket
 setPercentage (Task $task, int $percentage)
 Used by a job to notify his percentage. More...
 
 setCurrentTask (Task $task)
 
 setTask (Task $task)
 
 userInteraction (Option $option)
 Let the user interact with the bucket task queue. More...
 

Protected Member Functions

 replaceThunkValue (Task $currentTask, Value $resulting_value)
 In the structure of the task of this bucket the result of $currentTask is replaced with the $resulting_value. More...
 

Protected Attributes

int $user_id
 
Task $root_task
 
Task $current_task
 
array $tasks = []
 
int $state
 
int $total_number_of_tasks
 
array $percentages = []
 
string $title = ""
 
string $description = ""
 
int $percentage = 0
 
int $last_heartbeat = 0
 

Detailed Description

Definition at line 30 of file BasicBucket.php.

Member Function Documentation

◆ checkIntegrity()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::checkIntegrity ( )
Returns
bool Returns true if everything's alright. Throws an exception otherwise.
Exceptions
Exception

Implements ILIAS\BackgroundTasks\Bucket.

Definition at line 131 of file BasicBucket.php.

References ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\getTask(), and ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\getUserId().

131  : bool
132  {
133  if ($this->getUserId() === 0) {
134  foreach ($this->getTask()->unfoldTask() as $task) {
135  if ($task instanceof UserInteraction) {
136  throw new Exception("Your task contains user interactions and thus needs a user that observes the task.");
137  }
138  }
139  }
140 
141  return true;
142  }
+ Here is the call graph for this function:

◆ getCurrentTask()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::getCurrentTask ( )

◆ getDescription()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::getDescription ( )

◆ getLastHeartbeat()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::getLastHeartbeat ( )

When was the last time that something happened on this bucket?

Implements ILIAS\BackgroundTasks\Bucket.

Definition at line 227 of file BasicBucket.php.

References ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\$last_heartbeat.

227  : int
228  {
229  return $this->last_heartbeat;
230  }

◆ getOverallPercentage()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::getOverallPercentage ( )

◆ getState()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::getState ( )

Implements ILIAS\BackgroundTasks\Bucket.

Definition at line 126 of file BasicBucket.php.

References ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\$state.

Referenced by ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\userInteraction().

126  : int
127  {
128  return $this->state;
129  }
+ Here is the caller graph for this function:

◆ getTask()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::getTask ( )

◆ getTitle()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::getTitle ( )

◆ getUserId()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::getUserId ( )

Implements ILIAS\BackgroundTasks\Bucket.

Definition at line 47 of file BasicBucket.php.

Referenced by ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\checkIntegrity().

47  : int
48  {
49  return $this->user_id ?? 0;
50  }
+ Here is the caller graph for this function:

◆ hasCurrentTask()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::hasCurrentTask ( )

Implements ILIAS\BackgroundTasks\Bucket.

Definition at line 116 of file BasicBucket.php.

116  : bool
117  {
118  return isset($this->current_task);
119  }

◆ heartbeat()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::heartbeat ( )

There was something going on in the bucket, it's still working.

Implements ILIAS\BackgroundTasks\Bucket.

Definition at line 216 of file BasicBucket.php.

216  : void
217  {
218  $now = new \DateTime('now', new \DateTimeZone('UTC'));
219  $this->last_heartbeat = $now->getTimestamp();
220  }

◆ replaceThunkValue()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::replaceThunkValue ( Task  $currentTask,
Value  $resulting_value 
)
protected

In the structure of the task of this bucket the result of $currentTask is replaced with the $resulting_value.

Definition at line 176 of file BasicBucket.php.

References ILIAS\BackgroundTasks\Implementation\Values\AbstractValue\getParentTask(), and ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\getTask().

Referenced by ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\userInteraction().

176  : void
177  {
178  $tasks = $this->getTask()->unfoldTask();
179 
180  foreach ($tasks as $task) {
181  $newInputs = [];
182  foreach ($task->getInput() as $input) {
183  if ($input instanceof ThunkValue && $input->getParentTask() === $currentTask) {
184  $newInputs[] = $resulting_value;
185  } else {
186  $newInputs[] = $input;
187  }
188  }
189  $task->setInput($newInputs);
190  }
191  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCurrentTask()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::setCurrentTask ( Task  $task)

Definition at line 68 of file BasicBucket.php.

68  : void
69  {
70  $this->current_task = $task;
71  }

◆ setDescription()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::setDescription ( string  $description)

Definition at line 208 of file BasicBucket.php.

208  : void
209  {
210  $this->description = mb_substr($description, 0, 255);
211  }

◆ setLastHeartbeat()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::setLastHeartbeat ( int  $timestamp)

Implements ILIAS\BackgroundTasks\Bucket.

Definition at line 222 of file BasicBucket.php.

References $timestamp.

222  : void
223  {
224  $this->last_heartbeat = $timestamp;
225  }
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:70

◆ setOverallPercentage()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::setOverallPercentage ( int  $percentage)

◆ setPercentage()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::setPercentage ( Task  $task,
int  $percentage 
)

Definition at line 57 of file BasicBucket.php.

References ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\$percentage.

57  : void
58  {
59  $this->percentages[spl_object_hash($task)] = $percentage;
60  $this->calculateOverallPercentage();
61  }

◆ setState()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::setState ( int  $state)

Implements ILIAS\BackgroundTasks\Bucket.

Definition at line 106 of file BasicBucket.php.

References ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\$state.

Referenced by ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\userInteraction().

106  : void
107  {
108  $this->state = $state;
109  }
+ Here is the caller graph for this function:

◆ setTask()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::setTask ( Task  $task)

Definition at line 73 of file BasicBucket.php.

References ILIAS\BackgroundTasks\Task\unfoldTask().

73  : void
74  {
75  $this->tasks = $task->unfoldTask();
76  $this->total_number_of_tasks = count($this->tasks);
77  $this->root_task = $task;
78  foreach ($this->tasks as $subTask) {
79  $this->percentages[spl_object_hash($subTask)] = 0;
80  }
81  }
+ Here is the call graph for this function:

◆ setTitle()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::setTitle ( string  $title)

Definition at line 198 of file BasicBucket.php.

References ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\$title.

198  : void
199  {
200  $this->title = $title;
201  }

◆ setUserId()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::setUserId ( int  $user_id)

◆ userInteraction()

ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::userInteraction ( Option  $option)
Exceptions
Exception

Definition at line 147 of file BasicBucket.php.

References ILIAS\UI\Implementation\Component\Input\$inputs, ILIAS\BackgroundTasks\Implementation\Bucket\State\FINISHED, ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\getCurrentTask(), ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\getState(), ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\replaceThunkValue(), ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket\setState(), and ILIAS\BackgroundTasks\Implementation\Bucket\State\USER_INTERACTION.

147  : void
148  {
149  $currentTask = $this->getCurrentTask();
150 
151  if ($this->getState() != State::USER_INTERACTION) {
152  throw new Exception("Cannot continue a task that is not in the state 'user interaction'");
153  }
154  if (!$currentTask instanceof UserInteraction) {
155  // TODO: Maybe cleanup task?
156  throw new Exception("Observer is in an invalid state! state: userInteraction but current task is not a user interaction!");
157  }
158 
159  // From the current task we do the interaction.
160  $inputs = $currentTask->getInput();
161  $resulting_value = $currentTask->interaction($inputs, $option, $this);
162 
163  if ($currentTask === $this->root_task) {
164  // If this user interaction was the last thing to do, we set the state to finished. We can throw away the resulting value.
165  $this->setState(State::FINISHED);
166  } else {
167  // Then we replace the thunk value with the resulting value.
168  $this->replaceThunkValue($currentTask, $resulting_value);
169  }
170  }
replaceThunkValue(Task $currentTask, Value $resulting_value)
In the structure of the task of this bucket the result of $currentTask is replaced with the $resultin...
+ Here is the call graph for this function:

Field Documentation

◆ $current_task

Task ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::$current_task
protected

◆ $description

string ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::$description = ""
protected

◆ $last_heartbeat

int ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::$last_heartbeat = 0
protected

◆ $percentage

◆ $percentages

array ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::$percentages = []
protected

Definition at line 41 of file BasicBucket.php.

◆ $root_task

Task ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::$root_task
protected

◆ $state

int ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::$state
protected

◆ $tasks

array ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::$tasks = []
protected

Definition at line 38 of file BasicBucket.php.

◆ $title

string ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::$title = ""
protected

◆ $total_number_of_tasks

int ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::$total_number_of_tasks
protected

Definition at line 40 of file BasicBucket.php.

◆ $user_id

int ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket::$user_id
protected

The documentation for this class was generated from the following file: