Skip to content

Commit 8685a93

Browse files
committed
adding a timeout and better error handling
1 parent 63d40e4 commit 8685a93

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/PatternLab/Console/ProcessSpawner.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,28 @@ public function spawn($commands = array(), $quiet = false) {
6363
// if there are processes to spawn do so
6464
if (!empty($processes)) {
6565

66+
// get the time out
67+
$timeout = Config::getOption("timeout") ? (int)Config::getOption("timeout") : 30;
68+
6669
// start the processes
6770
foreach ($processes as $process) {
6871
$process["process"]->start();
72+
$process["process"]->setTimeout($timeout);
6973
}
7074

7175
// check on them and produce output
7276
while (true) {
7377
foreach ($processes as $process) {
74-
if ($process["process"]->isRunning()) {
75-
if (!$quiet && $process["output"]) {
76-
print $process["process"]->getIncrementalOutput();
78+
try {
79+
if ($process["process"]->isRunning()) {
80+
$process["process"]->checkTimeout();
81+
if (!$quiet && $process["output"]) {
82+
print $process["process"]->getIncrementalOutput();
83+
print $process["process"]->getIncrementalErrorOutput();
84+
}
7785
}
86+
} catch (\RuntimeException $e) {
87+
Console::writeError("pattern lab processes automatically time out after ".$timeout." seconds...");
7888
}
7989
}
8090
usleep(100000);

0 commit comments

Comments
 (0)