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

Scheduled tasks: Add link to clear fail delay

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      1. You will need to force a task to fail. To do this, we will make a temporary change to the code. Edit the file lib/classes/task/send_new_user_passwords_task.php and add the following line to the start of the execute() function: throw new \coding_exception('Broken on purpose');
      2. Run cron by your normal method, or simply wait for it to run if you have it set to run normally. Ideally, repeat three times (with some delay between). You want to have the task fail three times or more to make the times obvious.
      3. Look at the scheduled tasks page (Admin / Server / Scheduled tasks).
        • EXPECTED (no change): The \core\task\send_new_user_passwords_task row should include a fail delay time. The next scheduled run should for this task should be somewhat later than it would be normally (e.g. if the fail delay is 240 then the next run should be 4 minutes ahead of last attempt, whereas normally it runs once per minute).
        • EXPECTED: Below the fail delay there should be a new Clear link.
      4. Click on the Clear link.
        • EXPECTED: A confirmation screen should appear.
      5. Click the Clear button on the confirmation screen.
        • EXPECTED: The page reloads and you should see that the fail delay is now 0 and the next run is scheduled according to normal (so the next minute probably).
      6. Don't forget to remove the added test line from lib/classes/task/send_new_user_passwords_task.php.
      Show
      You will need to force a task to fail. To do this, we will make a temporary change to the code. Edit the file lib/classes/task/send_new_user_passwords_task.php and add the following line to the start of the execute() function: throw new \coding_exception('Broken on purpose'); Run cron by your normal method, or simply wait for it to run if you have it set to run normally. Ideally, repeat three times (with some delay between). You want to have the task fail three times or more to make the times obvious. Look at the scheduled tasks page ( Admin / Server / Scheduled tasks ). EXPECTED (no change): The \core\task\send_new_user_passwords_task row should include a fail delay time. The next scheduled run should for this task should be somewhat later than it would be normally (e.g. if the fail delay is 240 then the next run should be 4 minutes ahead of last attempt, whereas normally it runs once per minute). EXPECTED: Below the fail delay there should be a new Clear link. Click on the Clear link. EXPECTED: A confirmation screen should appear. Click the Clear button on the confirmation screen. EXPECTED: The page reloads and you should see that the fail delay is now 0 and the next run is scheduled according to normal (so the next minute probably). Don't forget to remove the added test line from lib/classes/task/send_new_user_passwords_task.php .
    • Affected Branches:
      MOODLE_35_STABLE
    • Fixed Branches:
      MOODLE_35_STABLE
    • Pull Master Branch:
      MDL-61063-master

      Description

      If a scheduled task throws an exception, its next run will be delayed (to prevent too many retries when something is broken). The 'fail delay' amount increases until it reaches 86,400 seconds (24 hours).

      Supposing that a system operator then corrects the problem. Because of the fail delay, the task will still wait up to 24 hours before retrying. It would be nice if the task starts running again according to its normal schedule, but there is no way to clear the fail delay except for manually editing the database table.

      I propose a link to clear the fail delay, from the scheduled tasks screen. The task will then run according to its normal schedule.

      (This is a small issue that annoyed me twice from an operational rather than development perspective recently, so I thought I would contribute an enhancement.)

      Note: As a workaround, you can use the 'Run now' feature to run the task immediately, and assuming it succeeds this will also clear the fail delay. However, in our setup, some tasks do not work well if run from the web browser like this. The CLI version of 'run now' also works and removes the web browser limitation, but again in our setup we don't have shell access to production servers... Basically I don't think this feature is in any way essential as there are workarounds (for us, updating it manually in the database and then editing the schedule settings is the easiest), it's just a nice-to-have.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                17/May/18