From 79dddb465b7208f61993cd0a34844e4c84ded247 Mon Sep 17 00:00:00 2001 From: fneumann Date: Mon, 30 Sep 2024 11:56:40 +0200 Subject: [PATCH] Fix #42183: Async background tasks fail silently Improve logging of async background task Check enabled soap to prevent orphaned background task entries Don't check the return value of the SOAP call This will be false in case of time-consuming background tasks. We have to keep the "fire and forget". --- .../TaskManager/AsyncTaskManager.php | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) 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; }