Skip to content

Commit 0c22a07

Browse files
committed
Implement Windows checking the task status
1 parent 2a00243 commit 0c22a07

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/AsyncTaskStatus.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,27 @@ private function findTaskRunnerProcess(): bool
205205
*/
206206
private function observeTaskRunnerProcess(): bool
207207
{
208+
// since we should have remembered the PID, we can just query whether it still exists
209+
// supposedly, the PID has not rolled over yet, right...?
208210
if (OsInfo::isWindows()) {
209-
// todo Windows
210-
return false;
211+
// Windows uses GCIM to discover processes
212+
$results = [];
213+
$tmpPsCmd = "Get-CimInstance Win32_Process -Filter \"CommandLine LIKE '%id=\'{$this->lastKnownPID}\'%'\" | Select ProcessId | Format-List";
214+
$status = exec("powershell -Command $tmpPsCmd", $results);
215+
if (!$status) {
216+
throw new RuntimeException("Could not query whether the AsyncTask is still running.");
217+
}
218+
// extract the PID
219+
$echoedPid = null;
220+
foreach ($results as $possiblePid) {
221+
if ($possiblePid == "") {
222+
continue;
223+
}
224+
$echoedPid = (int) $possiblePid;
225+
}
226+
return $this->lastKnownPID === $echoedPid;
211227
}
212228
// assume anything not Windows to be Unix
213-
// since we should have remembered the PID, we can just query whether it still exists
214-
// supposedly, the PID has not rolled over yet, right...?
215229
$echoedPid = exec("ps -p {$this->lastKnownPID} -o pid=");
216230
if ($echoedPid === false) {
217231
throw new RuntimeException("Could not query whether the AsyncTask is still running.");

0 commit comments

Comments
 (0)