Skip to content

Commit 423b007

Browse files
committed
MQE-1444: Allow MagentoCLI to bypass wait for process
- Implemented timeout logic to CLI command
1 parent 9b7d464 commit 423b007

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

etc/config/command.php

+22-7
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,32 @@
2727
$magentoBinary = $php . ' -f ../../../../bin/magento';
2828
$valid = validateCommand($magentoBinary, $command);
2929
if ($valid) {
30-
exec(
31-
escapeCommand($magentoBinary . " $command" . " $arguments") . " 2>&1",
32-
$output,
33-
$exitCode
34-
);
35-
if ($exitCode == 0) {
30+
$process = new Symfony\Component\Process\Process($magentoBinary . " $command" . " $arguments");
31+
$process->setIdleTimeout(60);
32+
$process->setTimeout(0);
33+
$idleTimeout = false;
34+
try {
35+
$process->run();
36+
$output = $process->getOutput();
37+
if (!$process->isSuccessful()) {
38+
$output = $process->getErrorOutput();
39+
}
40+
if (empty($output)) {
41+
$output = "CLI did not return output.";
42+
}
43+
44+
} catch (Symfony\Component\Process\Exception\ProcessTimedOutException $exception) {
45+
$output = "CLI command timed out, no output available.";
46+
$idleTimeout = true;
47+
}
48+
$exitCode = $process->getExitCode();
49+
50+
if ($exitCode == 0 || $idleTimeout) {
3651
http_response_code(202);
3752
} else {
3853
http_response_code(500);
3954
}
40-
echo implode("\n", $output);
55+
echo $output;
4156
} else {
4257
http_response_code(403);
4358
echo "Given command not found valid in Magento CLI Command list.";

0 commit comments

Comments
 (0)