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

On task install/upgrade, calculate next run time instead of running immediately

    XMLWordPrintable

Details

    • MOODLE_27_STABLE
    • MOODLE_27_STABLE, MOODLE_28_STABLE
    • MDL-48442-master
    • Hide
      1. copy the attached file to mod/forum/classes/task/cron_task2.php
      2. Add the following to mod/forum/db/tasks.php

            array(
                'classname' => 'mod_forum\task\cron_task2',
                'blocking' => 0,
                'minute' => '0',
                'hour' => '0',
                'day' => '1',
                'month' => '3',
                'dayofweek' => '*'
            ),
        

      3. Bump the version of mod forum by .01
      4. Run upgrade
      5. Go to Site administration / ►Server / ►Scheduled tasks
      6. Make sure you see a task with name "Test forum task" and next run time "Sunday, 1 March 2015, 12:00 AM"
      Show
      copy the attached file to mod/forum/classes/task/cron_task2.php Add the following to mod/forum/db/tasks.php array( 'classname' => 'mod_forum\task\cron_task2', 'blocking' => 0, 'minute' => '0', 'hour' => '0', 'day' => '1', 'month' => '3', 'dayofweek' => '*' ), Bump the version of mod forum by .01 Run upgrade Go to Site administration / ►Server / ►Scheduled tasks Make sure you see a task with name "Test forum task" and next run time "Sunday, 1 March 2015, 12:00 AM"
    • Team B Sprint 1

    Description

      When looking through the Task API, I noticed a potential problem: when tasks are added to the system or when the component has a version bump, then the task is scheduled to run ASAP. This means tasks that have very specific schedules would run at a random time for the first run and then subsequent runs would run according to the schedule. This could be bad if say, the point of the task was to send an email at midnight (according to its schedule), but the first run after install or every upgrade would send the email at a random time. To fix this, just calculate the next run time instead of using 0.

      Attachments

        Issue Links

          Activity

            People

              ankit_frenz Ankit Agarwal
              bushido Mark Nielsen
              Frédéric Massart Frédéric Massart
              Dan Poltawski Dan Poltawski
              Marina Glancy Marina Glancy
              David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                12/Jan/15