From ea1d370f4e5745f48df73fec144c41a7205b3085 Mon Sep 17 00:00:00 2001 From: Laurent Pinsivy Date: Wed, 19 Jun 2019 13:18:02 +0100 Subject: [PATCH] fix(remote-server): set task in failed if an error appears during import/export --- src/Centreon/Domain/Entity/Task.php | 1 + .../Application/Clapi/CentreonWorker.php | 36 ++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Centreon/Domain/Entity/Task.php b/src/Centreon/Domain/Entity/Task.php index 5092fe92447..4c2fab4a50b 100644 --- a/src/Centreon/Domain/Entity/Task.php +++ b/src/Centreon/Domain/Entity/Task.php @@ -19,6 +19,7 @@ class Task implements EntityInterface const STATE_PENDING = 'pending'; const STATE_PROGRESS = 'inprogress'; const STATE_COMPLETED = 'completed'; + const STATE_FAILED = 'failed'; /** * Task type diff --git a/src/CentreonRemote/Application/Clapi/CentreonWorker.php b/src/CentreonRemote/Application/Clapi/CentreonWorker.php index 735b3434db7..6a7517afd19 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";