From 0a3a9b0fca7e81c95d9367b07146fdac27dec303 Mon Sep 17 00:00:00 2001 From: Laurent Pinsivy Date: Thu, 4 Jul 2019 13:34:16 +0200 Subject: [PATCH] fix(remote-server): set task in failed if an error appears during import/export (#7634) Conflicts: src/Centreon/Domain/Entity/Task.php --- src/Centreon/Domain/Entity/Task.php | 9 ++--- .../Application/Clapi/CentreonWorker.php | 36 ++++++++++--------- 2 files changed, 25 insertions(+), 20 deletions(-) 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";