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

Be able to register and schedule adhoc tasks



    • Affected Branches:


      There are a number of use cases where we want to spawn lots of adhoc tasks, but have those tasks run to a specific schedule. The classic example is automated backups. We want them to run in parallel, but also only at certain times. Having parallel scheduled tasks was proposed in MDL-58279 but won't be done. So proposing this as a simpler solution that puts most of the burden onto the task system so that each use case doesn't have to implement it's own throttling or scheduler inside a scheduler.

      So my suggestion is:

      1) Any adhoc task can optionally also have an entry in/db/tasks

      2) The entry is identical to a scheduled task

      3) The task system knows from the type of the task that it is adhoc and so won't run it at that time

      4) The schedule can be fully managed exactly the same as normal scheduled tasks, in the gui and forced (see MDL-65843)

      5) If you call queue_adhoc_task and the task has no date then instead of defaulting to now it grabs the next time from the schedule

      6) If a task fails and its faildelay gets pushed back to a time which is no longer within the allowed schedule find the next time after that which matches

      7) If a task has been given an explicit time which is outside the schedule then defer it

      8) If due to max concurrency, or quality of service, the task system picks up an adhoc tasks it should double check that it is within the valid schedule, if it is not then push it back. This may also make 7 redundant as it has the same affect.

      The main thing to clearly communicate is that the cron schedule is semantically slightly different in that it is all the times that a task can be run, rather than simply the times that a task should start. So for automated backups as an example you might want the parent scheduled automated_backup_task to run at 1am in the morning every night:

      Minute Hour Day Day of week Month
      0 1 * * *

      But the async adhoc backup task needs to have a window of times it can run within, ie every minute from 1am to 6am

      Minute Hour Day Day of week Month
      * 1-6 * * *

      Side note: This adhoc backup tasks might need to be split so that automated backups can only run at night but human triggered backups run asap.



          Issue Links



              Unassigned Unassigned
              brendanheywood Brendan Heywood
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              4 Vote for this issue
              7 Start watching this issue