Skip to content

Commit

Permalink
Merge branch 'MDL-70568-cron-debugging-patch' of https://github.com/m…
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed May 11, 2022
2 parents 817db2b + 6770481 commit c7ddee0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/cronlib.php
Expand Up @@ -236,6 +236,7 @@ function cron_run_adhoc_tasks(int $timenow, $keepalive = 0, $checklimits = true)
*/
function cron_run_inner_scheduled_task(\core\task\task_base $task) {
global $CFG, $DB;
$debuglevel = $CFG->debug;

\core\task\manager::scheduled_task_starting($task);
\core\task\logmanager::start_logging($task);
Expand All @@ -250,6 +251,11 @@ function cron_run_inner_scheduled_task(\core\task\task_base $task) {
try {
get_mailer('buffer');
cron_prepare_core_renderer();
// Temporarily increase debug level if task has failed and debugging isn't already at maximum.
if ($debuglevel !== DEBUG_DEVELOPER && $faildelay = $task->get_fail_delay()) {
mtrace('Debugging increased temporarily due to faildelay of ' . $faildelay);
set_debugging(DEBUG_DEVELOPER);
}
$task->execute();
if ($DB->is_transaction_started()) {
throw new coding_exception("Task left transaction open");
Expand Down Expand Up @@ -280,6 +286,10 @@ function cron_run_inner_scheduled_task(\core\task\task_base $task) {
}
\core\task\manager::scheduled_task_failed($task);
} finally {
// Reset debugging if it changed.
if ($CFG->debug !== $debuglevel) {
set_debugging($debuglevel);
}
// Reset back to the standard admin user.
cron_setup_user();
cron_set_process_title('Waiting for next scheduled task');
Expand All @@ -294,7 +304,8 @@ function cron_run_inner_scheduled_task(\core\task\task_base $task) {
* @param \core\task\adhoc_task $task
*/
function cron_run_inner_adhoc_task(\core\task\adhoc_task $task) {
global $DB, $CFG;
global $CFG, $DB;
$debuglevel = $CFG->debug;

\core\task\manager::adhoc_task_starting($task);
\core\task\logmanager::start_logging($task);
Expand Down Expand Up @@ -338,6 +349,11 @@ function cron_run_inner_adhoc_task(\core\task\adhoc_task $task) {
try {
get_mailer('buffer');
cron_prepare_core_renderer();
// Temporarily increase debug level if task has failed and debugging isn't already at maximum.
if ($debuglevel !== DEBUG_DEVELOPER && $faildelay = $task->get_fail_delay()) {
mtrace('Debugging increased temporarily due to faildelay of ' . $faildelay);
set_debugging(DEBUG_DEVELOPER);
}
$task->execute();
if ($DB->is_transaction_started()) {
throw new coding_exception("Task left transaction open");
Expand Down Expand Up @@ -368,6 +384,10 @@ function cron_run_inner_adhoc_task(\core\task\adhoc_task $task) {
}
\core\task\manager::adhoc_task_failed($task);
} finally {
// Reset debug level if it changed.
if ($CFG->debug !== $debuglevel) {
set_debugging($debuglevel);
}
// Reset back to the standard admin user.
cron_setup_user();
cron_prepare_core_renderer(true);
Expand Down

0 comments on commit c7ddee0

Please sign in to comment.