MDL-72775 tool_task: check long running tasks
This commit is contained in:
@@ -26,6 +26,7 @@ namespace core\task;
|
||||
|
||||
use core_component;
|
||||
use core_plugin_manager;
|
||||
use core\check\result;
|
||||
|
||||
/**
|
||||
* Abstract class for common properties of scheduled_task and adhoc_task.
|
||||
@@ -257,4 +258,40 @@ abstract class task_base {
|
||||
return $plugininfo && ($plugininfo->is_enabled() !== false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns task runtime
|
||||
* @return int
|
||||
*/
|
||||
public function get_runtime() {
|
||||
return time() - $this->timestarted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the task has been running for too long
|
||||
* @return result
|
||||
*/
|
||||
public function get_runtime_result() {
|
||||
global $CFG;
|
||||
$runtime = $this->get_runtime();
|
||||
$runtimeerror = $CFG->taskruntimeerror;
|
||||
$runtimewarn = $CFG->taskruntimewarn;
|
||||
|
||||
$status = result::OK;
|
||||
$details = '';
|
||||
|
||||
if ($runtime > $runtimewarn) {
|
||||
$status = result::WARNING;
|
||||
$details = get_string('slowtask', 'tool_task', format_time($runtimewarn));
|
||||
}
|
||||
|
||||
if ($runtime > $runtimeerror) {
|
||||
$status = result::ERROR;
|
||||
$details = get_string('slowtask', 'tool_task', format_time($runtimeerror));
|
||||
}
|
||||
|
||||
// This result is aggregated with other running tasks checks before display.
|
||||
return new result($status, '', $details);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user