-
Improvement
-
Resolution: Fixed
-
Minor
-
3.7
-
MOODLE_37_STABLE
-
MOODLE_37_STABLE
-
MDL-64454-master -
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.