Skip to content

Commit de2e156

Browse files
committed
Add waiting logic
1 parent b6d876d commit de2e156

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

.github/nightly.php

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,34 @@ function (): iterable {
108108
2
109109
];
110110

111+
$finalStatus = 0;
111112
$parentPids = [];
113+
114+
$waitOne = function () use (&$finalStatus, &$parentPids): void {
115+
$res = pcntl_wait($status);
116+
if ($res === -1) {
117+
printMutex("An error occurred while waiting with waitpid!");
118+
$finalStatus = 1;
119+
return;
120+
}
121+
if (!isset($parentPids[$res])) {
122+
printMutex("Unknown PID $res returned!");
123+
$finalStatus = 1;
124+
return;
125+
}
126+
unset($parentPids[$res]);
127+
if ($status !== 0) {
128+
$finalStatus = $status;
129+
}
130+
};
131+
112132
foreach ($repos as $dir => [$repo, $branch, $prepare, $command, $repeat]) {
113133
$pid = pcntl_fork();
114134
if ($pid) {
115-
$parentPids []= $pid;
135+
$parentPids[$pid] = true;
136+
if (count($parentPids) > $parallel) {
137+
$waitOne();
138+
}
116139
continue;
117140
}
118141

@@ -173,14 +196,8 @@ function (): iterable {
173196
exit($final);
174197
}
175198

176-
$final = 0;
177-
foreach ($parentPids as $pid) {
178-
$status = 0;
179-
if (pcntl_waitpid($pid, $status) === -1) {
180-
printMutex("An error occurred while waiting with waitpid!");
181-
}
182-
if ($status !== 0) {
183-
$final = $status;
184-
}
199+
while ($parentPids) {
200+
$waitOne();
185201
}
186-
die($final);
202+
203+
die($finalStatus);

0 commit comments

Comments
 (0)