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

fix(remote-server): set task in failed status if an error appears #7634

Merged
merged 1 commit into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
lpinsivy marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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);
/**
victorvassilev marked this conversation as resolved.
Show resolved Hide resolved
* 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