MDL-80309 tasks: Clean up mtrace logs
This commit is contained in:
@@ -37,3 +37,13 @@ function tool_task_status_checks() : array {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Function used to handle mtrace by outputting the text to normal browser window.
|
||||
*
|
||||
* @param string $message Message to output
|
||||
* @param string $eol End of line character
|
||||
*/
|
||||
function tool_task_mtrace_wrapper(string $message, string $eol): void {
|
||||
$message = s($message);
|
||||
echo $message . $eol;
|
||||
}
|
||||
|
||||
@@ -30,16 +30,6 @@ require('../../../config.php');
|
||||
|
||||
require_once($CFG->libdir.'/cronlib.php');
|
||||
|
||||
/**
|
||||
* Function used to handle mtrace by outputting the text to normal browser window.
|
||||
*
|
||||
* @param string $message Message to output
|
||||
* @param string $eol End of line character
|
||||
*/
|
||||
function tool_task_mtrace_wrapper($message, $eol) {
|
||||
echo s($message . $eol);
|
||||
}
|
||||
|
||||
// Allow execution of single task. This requires login and has different rules.
|
||||
$taskname = required_param('task', PARAM_RAW_TRIMMED);
|
||||
|
||||
@@ -97,6 +87,7 @@ require_sesskey();
|
||||
|
||||
// Prepare to handle output via mtrace.
|
||||
echo html_writer::start_tag('pre');
|
||||
require('lib.php');
|
||||
$CFG->mtrace_wrapper = 'tool_task_mtrace_wrapper';
|
||||
|
||||
// Run the specified task (this will output an error if it doesn't exist).
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user