Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(remote-server): set task in failed if an error appears during imp…
Browse files Browse the repository at this point in the history
…ort/export (#7634)
  • Loading branch information
lpinsivy committed Jul 4, 2019
1 parent 53ac5dd commit de4aa35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/Centreon/Domain/Entity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 20 additions & 16 deletions src/CentreonRemote/Application/Clapi/CentreonWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand All @@ -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";
Expand Down

0 comments on commit de4aa35

Please sign in to comment.