Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-51109

When scheduled task fails no debug info is provided

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Expected output: For all tests, repeat with $CFG->debug set to DEBUG_DEVELOPER and then at a lower level, debug info should only be displayed in developer mode.

      1. Install the attached local plugin.
      2. Run $ php admin/tool/task/cli/schedule_task.php --execute=\\local_breaktask\\task
        brokenphp
        and ensure the expected output is seen
      3. Run php admin/tool/task/cli/schedule_task.php --execute=\\local_breaktask\\task
        brokendb
        and ensure the expected output is seen
      4. Run php admin/tool/task/cli/schedule_task.php --execute=\\local_breaktask\\task
        brokenexception
        and ensure the expected output is seen
      5. Run cron and ensure the three above tasks are failed and ensure expected output is seen
      Show
      Expected output: For all tests, repeat with $CFG->debug set to DEBUG_DEVELOPER and then at a lower level, debug info should only be displayed in developer mode. Install the attached local plugin. Run $ php admin/tool/task/cli/schedule_task.php --execute=\\local_breaktask\\task brokenphp and ensure the expected output is seen Run php admin/tool/task/cli/schedule_task.php --execute=\\local_breaktask\\task brokendb and ensure the expected output is seen Run php admin/tool/task/cli/schedule_task.php --execute=\\local_breaktask\\task brokenexception and ensure the expected output is seen Run cron and ensure the three above tasks are failed and ensure expected output is seen
    • Affected Branches:
      MOODLE_28_STABLE, MOODLE_29_STABLE
    • Fixed Branches:
      MOODLE_28_STABLE, MOODLE_29_STABLE
    • Pull Master Branch:
      MDL-51109-master

      Description

      When a scheduled task fails with some sort of database issue (see MDLSITE-4145 for one example where an index is being violated, you could write a basic bit of code to demonstrate it, but haven't got time right now), the exception handler traps the error but prevents an useful output - even in DEBUG_DEVELOPER mode.

      To find what was going wrong I had to do:

      diff --git a/admin/tool/task/cli/schedule_task.php b/admin/tool/task/cli/schedule_task.php
      index 6904d48..f5700a6 100644
      --- a/admin/tool/task/cli/schedule_task.php
      +++ b/admin/tool/task/cli/schedule_task.php
      @@ -148,7 +148,7 @@ if ($execute = $options['execute']) {
               }
               mtrace("... used " . ($DB->perf_get_queries() - $predbqueries) . " dbqueries");
               mtrace("... used " . (microtime(true) - $pretime) . " seconds");
      -        mtrace("Task failed: " . $e->getMessage());
      +        mtrace("Task failed: " . $e->getMessage().$e->debuginfo);
               \core\task\manager::scheduled_task_failed($task);
               get_mailer('close');
               exit(1);
      

      There should be a way to see that error without having to hack code. We could do it only in the cli runner, or when debug mode is set, etc.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                3 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  14/Sep/15