diff --git a/src/Centreon/Domain/Entity/Task.php b/src/Centreon/Domain/Entity/Task.php index d939cfaf007..38072a60260 100644 --- a/src/Centreon/Domain/Entity/Task.php +++ b/src/Centreon/Domain/Entity/Task.php @@ -16,9 +16,10 @@ class Task implements EntityInterface /** * Task states */ - CONST STATE_PENDING = 'pending'; - CONST STATE_PROGRESS = 'inprogress'; - CONST STATE_COMPLETED = 'completed'; + const STATE_PENDING = 'pending'; + const STATE_PROGRESS = 'inprogress'; + const STATE_COMPLETED = 'completed'; + const STATE_FAILED = 'failed'; /** * Task type @@ -226,4 +227,4 @@ private function array_filter_key($input, $callback) return $input; } -} \ No newline at end of file +} diff --git a/src/CentreonRemote/Application/Clapi/CentreonWorker.php b/src/CentreonRemote/Application/Clapi/CentreonWorker.php index 476c707a270..32cbd50e186 100644 --- a/src/CentreonRemote/Application/Clapi/CentreonWorker.php +++ b/src/CentreonRemote/Application/Clapi/CentreonWorker.php @@ -75,22 +75,24 @@ private function processExportTasks(): void try { $this->getDi()['centreon_remote.export']->export($commitment); - } catch (\Exception $e) { - echo $e->getMessage() . "\n"; - } - $this->getDi()['centreon.taskservice']->updateStatus($task->getId(), Task::STATE_COMPLETED); + $this->getDi()['centreon.taskservice']->updateStatus($task->getId(), Task::STATE_COMPLETED); - /** - * move export file - */ - $cmd = new Command(); - $compositeKey = $params['server'] . ':' . $task->getId(); - $cmd->setCommandLine(Command::COMMAND_TRANSFER_EXPORT_FILES . $compositeKey); - $cmdService = new CentcoreCommandService(); - $cmdWritten = $cmdService->sendCommand($cmd); + /** + * move export file + */ + $cmd = new Command(); + $compositeKey = $params['server'] . ':' . $task->getId(); + $cmd->setCommandLine(Command::COMMAND_TRANSFER_EXPORT_FILES . $compositeKey); + $cmdService = new CentcoreCommandService(); + $cmdWritten = $cmdService->sendCommand($cmd); - echo "finished.\n"; + echo "{$datetime} - finished.\n"; + } catch (\Exception $e) { + echo $e->getMessage() . "\n"; + echo "{$datetime} - task #" . $task->getId() . " aborted\n"; + $this->getDi()['centreon.taskservice']->updateStatus($task->getId(), Task::STATE_FAILED); + } } } @@ -116,12 +118,14 @@ private function processImportTasks(): void try { $this->getDi()['centreon_remote.export']->import(); + + $this->getDi()['centreon.taskservice']->updateStatus($task->getId(), Task::STATE_COMPLETED); + echo "{$datetime} - finished.\n"; } catch (\Exception $e) { echo $e->getMessage() . "\n"; + echo "{$datetime} - task #" . $task->getId() . " aborted\n"; + $this->getDi()['centreon.taskservice']->updateStatus($task->getId(), Task::STATE_FAILED); } - $this->getDi()['centreon.taskservice']->updateStatus($task->getId(), Task::STATE_COMPLETED); - - echo "finished.\n"; } echo "{$datetime} - Worker cycle completed.\n";