diff --git a/src/BackgroundTasks/Implementation/TaskManager/AsyncTaskManager.php b/src/BackgroundTasks/Implementation/TaskManager/AsyncTaskManager.php index 7ad8bbcb4781..25a1e466e02a 100644 --- a/src/BackgroundTasks/Implementation/TaskManager/AsyncTaskManager.php +++ b/src/BackgroundTasks/Implementation/TaskManager/AsyncTaskManager.php @@ -23,6 +23,7 @@ use ILIAS\BackgroundTasks\Implementation\Tasks\UserInteraction\UserInteractionRequiredException; use ILIAS\BackgroundTasks\Implementation\Tasks\UserInteraction\UserInteractionSkippedException; use ILIAS\BackgroundTasks\Task\UserInteraction; +use ILIAS\Export\ImportStatus\Exception\ilException; class AsyncTaskManager extends BasicTaskManager { @@ -36,11 +37,19 @@ public function run(Bucket $bucket): void { global $DIC; + // check this before saving the bucket state to prevent an orphaned entry with 0% + if (!$DIC->settings()->get('soap_user_administration')) { + $DIC->logger()->bgtk()->warning("SOAP not enabled, fallback to sync version"); + $sync_manager = new SyncTaskManager($this->persistence); + $sync_manager->run($bucket); + return; + } + $bucket->setState(State::SCHEDULED); $bucket->setCurrentTask($bucket->getTask()); $DIC->backgroundTasks()->persistence()->saveBucketAndItsTasks($bucket); - $DIC->logger()->root()->info("[BT] Trying to call webserver"); + $DIC->logger()->bgtk()->info("Trying to call webserver"); // Call SOAP-Server $soap_client = new \ilSoapClient(); @@ -63,12 +72,13 @@ public function run(Bucket $bucket): void $session_id . '::' . $client_id, )); } catch (\Throwable $t) { - $DIC->logger()->root()->info("[BT] Calling Webserver failed, fallback to sync version"); + $DIC->logger()->bgtk()->warning($t->getMessage()); + $DIC->logger()->bgtk()->warning("Calling webserver failed, fallback to sync version"); $sync_manager = new SyncTaskManager($this->persistence); $sync_manager->run($bucket); - } finally { - $DIC->logger()->root()->info("[BT] Calling webserver successful"); + return; } + $DIC->logger()->bgtk()->info("Calling webserver successful"); } /** @@ -81,13 +91,13 @@ public function runAsync() $n_of_tasks = $ilIliasIniFile->readVariable("background_tasks", "number_of_concurrent_tasks"); $n_of_tasks = $n_of_tasks ? $n_of_tasks : 5; - $DIC->logger()->root()->info("[BackgroundTask] Starting background job."); + $DIC->logger()->bgtk()->info("Starting background job."); $persistence = $DIC->backgroundTasks()->persistence(); // TODO search over all clients. $MAX_PARALLEL_JOBS = $n_of_tasks; if (count($persistence->getBucketIdsByState(State::RUNNING)) >= $MAX_PARALLEL_JOBS) { - $DIC->logger()->root()->info("[BT] Too many running jobs, worker going down."); + $DIC->logger()->bgtk()->info("Too many running jobs, worker going down."); return; } @@ -114,14 +124,14 @@ public function runAsync() $this->persistence->saveBucketAndItsTasks($bucket); } catch (\Exception $e) { $persistence->deleteBucket($bucket); - $DIC->logger()->root()->info("[BT] Exception while async computing: " + $DIC->logger()->bgtk()->info("Exception while async computing: " . $e->getMessage()); - $DIC->logger()->root()->info("[BT] Stack Trace: " + $DIC->logger()->bgtk()->info("Stack Trace: " . $e->getTraceAsString()); } } - $DIC->logger()->root()->info("[BT] One worker going down because there's nothing left to do."); + $DIC->logger()->bgtk()->info("One worker going down because there's nothing left to do."); return true; }