ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\BackgroundTasks\Implementation\TaskManager\AsyncTaskManager Class Reference
+ Inheritance diagram for ILIAS\BackgroundTasks\Implementation\TaskManager\AsyncTaskManager:
+ Collaboration diagram for ILIAS\BackgroundTasks\Implementation\TaskManager\AsyncTaskManager:

Public Member Functions

 run (Bucket $bucket)
 This will add an Observer of the Task and start running the task. More...
 
 runAsync ()
 
- Public Member Functions inherited from ILIAS\BackgroundTasks\Implementation\TaskManager\BasicTaskManager
 __construct (protected Persistence $persistence)
 
 continueTask (Bucket $bucket, Option $option)
 Continue a task with a given option. More...
 
 quitBucket (Bucket $bucket)
 Quits and deletes a Bucket with all it's Jobs. More...
 
- Public Member Functions inherited from ILIAS\BackgroundTasks\TaskManager
 executeTask (Task $task, Observer $observer)
 Actually executes a task. More...
 
 run (Bucket $bucket)
 Depending on your background task settings, executes or puts the task into the queue. More...
 
 continueTask (Bucket $bucket, Option $option)
 Continue a task that is the state UserInteraction with a given option. More...
 
 quitBucket (Bucket $bucket)
 Quits and deletes a Bucket with all it's Jobs. More...
 

Data Fields

const CMD_START_WORKER = 'startBackgroundTaskWorker'
 

Detailed Description

Definition at line 26 of file AsyncTaskManager.php.

Member Function Documentation

◆ run()

ILIAS\BackgroundTasks\Implementation\TaskManager\AsyncTaskManager::run ( Bucket  $bucket)

This will add an Observer of the Task and start running the task.

Exceptions

Exception

Implements ILIAS\BackgroundTasks\TaskManager.

Definition at line 34 of file AsyncTaskManager.php.

34 : void
35 {
36 global $DIC;
37
38 // check this before saving the bucket state to prevent an orphaned entry with 0%
39 if (!$DIC->settings()->get('soap_user_administration')) {
40 $DIC->logger()->bgtk()->warning("SOAP not enabled, fallback to sync version");
41 $sync_manager = new SyncTaskManager($this->persistence);
42 $sync_manager->run($bucket);
43 return;
44 }
45
46 $bucket->setState(State::SCHEDULED);
47 $bucket->setCurrentTask($bucket->getTask());
48 $DIC->backgroundTasks()->persistence()->saveBucketAndItsTasks($bucket);
49
50 $DIC->logger()->bgtk()->info("Trying to call webserver");
51
52 // Call SOAP-Server
53 $soap_client = new \ilSoapClient();
54 $soap_client->setResponseTimeout(0);
55 $soap_client->enableWSDL(true);
56 $soap_client->init();
57 $session_id = session_id();
58 $client_id = $DIC->http()->wrapper()->cookie()->retrieve(
59 'ilClientId',
60 $DIC->refinery()->byTrying([
61 $DIC->refinery()->kindlyTo()->string(),
62 $DIC->refinery()->always(
63 defined('CLIENT_ID') ? CLIENT_ID : null
64 )
65 ])
66 );
67
68 try {
69 $soap_client->call(self::CMD_START_WORKER, [
70 $session_id . '::' . $client_id,
71 ]);
72 } catch (\Throwable $t) {
73 $DIC->logger()->bgtk()->warning($t->getMessage());
74 $DIC->logger()->bgtk()->warning("Calling webserver failed, fallback to sync version");
75 $sync_manager = new SyncTaskManager($this->persistence);
76 $sync_manager->run($bucket);
77 return;
78 }
79 $DIC->logger()->bgtk()->info("Calling webserver successful");
80 }
string $client_id
Definition: class.ilias.php:36
const CLIENT_ID
Definition: constants.php:41
global $DIC
Definition: shib_login.php:26

References ILIAS\$client_id, $DIC, CLIENT_ID, ILIAS\BackgroundTasks\Bucket\getTask(), ILIAS\BackgroundTasks\Implementation\Bucket\State\SCHEDULED, ILIAS\BackgroundTasks\Bucket\setCurrentTask(), and ILIAS\BackgroundTasks\Bucket\setState().

+ Here is the call graph for this function:

◆ runAsync()

ILIAS\BackgroundTasks\Implementation\TaskManager\AsyncTaskManager::runAsync ( )
Returns
bool|null

Definition at line 85 of file AsyncTaskManager.php.

85 : ?bool
86 {
87 global $DIC, $ilIliasIniFile;
88
89 $n_of_tasks = $ilIliasIniFile->readVariable("background_tasks", "number_of_concurrent_tasks");
90 $n_of_tasks = $n_of_tasks ?: 5;
91
92 $DIC->logger()->bgtk()->info("Starting background job.");
93 $persistence = $DIC->backgroundTasks()->persistence();
94
95 // TODO search over all clients.
96 $MAX_PARALLEL_JOBS = $n_of_tasks;
97 if (count($persistence->getBucketIdsByState(State::RUNNING)) >= $MAX_PARALLEL_JOBS) {
98 $DIC->logger()->bgtk()->info("Too many running jobs, worker going down.");
99
100 return null;
101 }
102
103 while (true) {
104 $ids = $persistence->getBucketIdsByState(State::SCHEDULED);
105 if (count($ids) === 0) {
106 break;
107 }
108
109 $bucket = $persistence->loadBucket(array_shift($ids));
110 $observer = new PersistingObserver($bucket, $persistence);
111 $task = $bucket->getTask();
112
113 try {
114 $this->executeTask($task, $observer);
115 $bucket->setState(State::FINISHED);
116 $this->persistence->updateBucket($bucket);
117 } catch (UserInteractionSkippedException) {
118 $bucket->setState(State::FINISHED);
119 $this->persistence->deleteBucket($bucket);
120 } catch (UserInteractionRequiredException) {
121 // We're okay!
122 $this->persistence->saveBucketAndItsTasks($bucket);
123 } catch (\Exception $e) {
124 $persistence->deleteBucket($bucket);
125 $DIC->logger()->bgtk()->info("Exception while async computing: "
126 . $e->getMessage());
127 $DIC->logger()->bgtk()->info("Stack Trace: "
128 . $e->getTraceAsString());
129 }
130 }
131
132 $DIC->logger()->bgtk()->info("One worker going down because there's nothing left to do.");
133
134 return true;
135 }
executeTask(Task $task, Observer $observer)
Actually executes a task.
$ilIliasIniFile
Definition: server.php:37

References $DIC, Vendor\Package\$e, $ilIliasIniFile, ILIAS\BackgroundTasks\TaskManager\executeTask(), ILIAS\BackgroundTasks\Implementation\Bucket\State\FINISHED, ILIAS\BackgroundTasks\Implementation\Bucket\State\RUNNING, and ILIAS\BackgroundTasks\Implementation\Bucket\State\SCHEDULED.

+ Here is the call graph for this function:

Field Documentation

◆ CMD_START_WORKER

const ILIAS\BackgroundTasks\Implementation\TaskManager\AsyncTaskManager::CMD_START_WORKER = 'startBackgroundTaskWorker'

Definition at line 28 of file AsyncTaskManager.php.


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