private function SjApiClient::executeSjAdd in Acquia Cloud Site Factory Connector 8.2
Same name and namespace in other branches
- 8 acsf_sj/src/Api/SjApiClient.php \Drupal\acsf_sj\Api\SjApiClient::executeSjAdd()
Executes the sjadd command.
Parameters
string $command_arguments: The arguments to the sjadd command, already escaped for shell execution.
Return value
bool Whether the command was executed successfully.
1 call to SjApiClient::executeSjAdd()
- SjApiClient::addJob in acsf_sj/
src/ Api/ SjApiClient.php - Adds a scheduled job.
File
- acsf_sj/
src/ Api/ SjApiClient.php, line 181
Class
- SjApiClient
- Provides a Scheduled Jobs API client.
Namespace
Drupal\acsf_sj\ApiCode
private function executeSjAdd($command_arguments) {
$error = '';
if (!$this->binary) {
$error = "The installation path for the ACSF 'sjadd' binary cannot be determined.";
}
elseif (!is_executable($this->binary)) {
$error = "The ACSF 'sjadd' binary is missing or not executable, preventing adding a scheduled job.";
}
$exit_code = -1;
if (!$error) {
$command = sprintf('%s %s', $this->binary, $command_arguments);
// Possibly one retry.
for ($retry = 0; $retry < 2 && $exit_code !== 0; $retry++) {
if ($retry) {
$this->logger
->log(LogLevel::WARNING, "Command '@command' will be re-run; it exited with code @code:\n@error", [
'@command' => $command,
'@code' => $exit_code,
'@error' => $error,
]);
// Retry after half of a second.
usleep(500000);
}
try {
$process = new Process($command);
// We're hardcoding a timeout of 10 seconds for just scheduling the
// job (rather than for executing the scheduled job).
$process
->setTimeout(10);
$process
->run();
$exit_code = $process
->getExitCode();
if ($exit_code !== 0) {
$error = $process
->getErrorOutput();
}
} catch (\Exception $e) {
$error = $e
->getMessage();
}
}
}
if ($exit_code !== 0) {
// This message is not completely accurate for code -1, but that's OK.
// @error can be any single or multi-line output, so place on a new line.
$this->logger
->log(LogLevel::ERROR, "Command '@command' exited with code @code:\n@error", [
'@command' => $command ?? '-',
'@code' => $exit_code,
'@error' => $error,
]);
}
return $exit_code === 0;
}