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)

Conflicts:
	src/Centreon/Domain/Entity/Task.php
  • Loading branch information
lpinsivy committed Jul 4, 2019
1 parent 7a70e98 commit 0a3a9b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
9 changes: 5 additions & 4 deletions src/Centreon/Domain/Entity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -226,4 +227,4 @@ private function array_filter_key($input, $callback)

return $input;
}
}
}
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 0a3a9b0

Please sign in to comment.