MDL-80309 tasks: Clean up mtrace logs

This commit is contained in:
Brendan Heywood
2023-12-07 12:07:45 +08:00
committed by Jun Pataleta
parent 7762fc61e8
commit 628e7ecc4c
3 changed files with 40 additions and 11 deletions
+29 -1
View File
@@ -1392,12 +1392,40 @@ class manager {
$command = "{$phpbinary} {$scriptpath} {$taskarg}";
// Execute it.
passthru($command);
self::passthru_via_mtrace($command);
}
return true;
}
/**
* This behaves similar to passthru but filters every line via
* the mtrace function so it can be post processed.
*
* @param string $command to run
* @return void
*/
public static function passthru_via_mtrace(string $command) {
$descriptorspec = [
0 => ['pipe', 'r'], // STDIN.
1 => ['pipe', 'w'], // STDOUT.
2 => ['pipe', 'w'], // STDERR.
];
flush();
$process = proc_open($command, $descriptorspec, $pipes, realpath('./'), []);
if (is_resource($process)) {
while ($s = fgets($pipes[1])) {
mtrace($s, '');
flush();
}
}
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
}
/**
* For a given scheduled task record, this method will check to see if any overrides have
* been applied in config and return a copy of the record with any overridden values.