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

Admin: Admin screen should show warning if cron does not run frequently

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      1. If your system runs cron regularly, temporarily turn this off to make testing easier.
      2. Run cron (from terminal, execute {{php admin/cli/cron.php }}).
      3. Run cron again. (This should make the interval between runs very short.)
      4. Go to the admin page.
        • EXPECTED: You should not see a warning about running cron.
      5. Wait at least 200 seconds.
      6. Run cron again. (The interval should now be at least 200 seconds, plus however long the last cron run took.)
      7. Reload the admin page.
        • EXPECTED: You should now see a warning about running cron frequently. This warning has a help icon with more information (it's the same message already used for the 24 hour warning).
      8. Run cron again (this has to be done within about three minutes or less of the previous cron run).
      9. Reload the admin page.
        • EXPECTED: The message should have disappeared again.
      Show
      If your system runs cron regularly, temporarily turn this off to make testing easier. Run cron (from terminal, execute {{php admin/cli/cron.php }}). Run cron again. (This should make the interval between runs very short.) Go to the admin page. EXPECTED: You should not see a warning about running cron. Wait at least 200 seconds. Run cron again. (The interval should now be at least 200 seconds, plus however long the last cron run took.) Reload the admin page. EXPECTED: You should now see a warning about running cron frequently. This warning has a help icon with more information (it's the same message already used for the 24 hour warning). Run cron again (this has to be done within about three minutes or less of the previous cron run). Reload the admin page. EXPECTED: The message should have disappeared again.
    • Affected Branches:
      MOODLE_37_STABLE
    • Fixed Branches:
      MOODLE_37_STABLE
    • Pull Master Branch:
      MDL-64454-master

      Description

      Moodle recommends that cron is run once per minute (so that long-running cron tasks potentially overlap), and this is becoming increasingly important due to more use of ad-hoc tasks. We suspect there are many systems (including the OU's) which were configured before the new task system when the recommendation was different, so that cron runs only infrequently, and which have not been changed in the years since.

      The admin screen warns if you haven't run cron in 24 hours. This should be extended so that it also warns if you haven't run it very frequently (I suggest 3 minutes) as a prompt to administrators to configure their systems better.

      As part of this change we actually need to record how cron runs using a couple of config variables because the previous way of counting it (check last scheduled task run) doesn't really work in this frequency - it's possible that no task was scheduled to run in a particular cron, at least if the configuration has been modified.

      The new logic is:

      • Only if not showing the existing (24 hours) warning:
        • If the gap between the most recent 2 cron runs was more than 200 seconds
        • OR the most recent cron run was more than 200 seconds ago
        • Then show a warning about infrequent runs

      The reason for tracking the interval, as well as the most recent, is simply to make the warning consistent; for example if you run cron every 10 minutes (600 seconds) then the warning will appear every time you look at the admin page, whereas if we only checked the last run time, it would have a 2/3 chance of appearing.

      This change has the added benefit that a message appears on the admin page very promptly if cron has stopped being run for some reason (something that happens with depressing regularity in our test environments), rather than only after 24 hours.

      Note: After updating to a version containing this change, the system will incorrectly show the existing warning about cron not having run for 24 hours, until the first time cron runs. I don't think this is a major problem.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                20/May/19

                Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour
                1h