We are having various problems (none really serious so far, but quite annoying) around management of test and live systems due to increased use of ad-hoc tasks in Moodle. 'Normal' scheduled tasks are highly controllable, as they can be disabled (which may cause some Moodle behaviour not to work but we can make an informed decision about that) or set to run only at certain times; ad-hoc tasks are not at all controllable and can also cause problems when they fail.
I don't necessarily have time to develop this right away but may be interested in doing it when I get a chance, so I thought it might be worth posting this for comment, then me (or somebody else) can pick it up if people like it.
I propose there should be a user interface (in an area of the same scheduled tasks page, or on a similar page in the same area) allowing control of ad-hoc tasks for advanced system administrators.
1. Show a list of all ad-hoc tasks that have run in the past 6 months (task name, as there is no 'friendly' display name).
2. Show most recent run date/time, the time it took, if there was an error or not, and total number of runs this week (since the start of the most recent ISO UTC week; so it gets cleared to zero periodically).
3. Offer options to disable a task or to restrict its running to specfic times - similar to the scheduled task interface, except that obviously the task would not necessarily run at those times, only if one or more instances are pending.
This could be implemented with no API changes, only a new database table that stores information about recent runs of ad-hoc tasks. The table structure could be:
- task name (class name)
- last run (start date and time)
- last run (elapsed time taken to complete task)
- last run success/failure
- count of runs this week - success and failure
- disabled yes/no
- time fields (cron format, as per scheduled tasks table)
There would be a new scheduled task running weekly which would zero the run counts and clear old (> 6 months) entries from the table. If you upgrade to a new Moodle version, tasks from older versions that aren't relevant any more would still appear in the list for 3 months, but admins can tell from the last run time that they haven't run recently.
Settings will be lost if a task doesn't run for 6 months, but how many tasks run that infrequently (and how much are we likely to care about configuring them if so).