Scheduled tasks are tasks that are run at a certain time or set interval. For example, notify a page owner that their page is about to expire.

Scheduled tasks are implemented as singleton instances and a single instance is responsibly directly or indirectly for executing all tasks that should be run at that time.

There are three scheduled interval at the moment: Daily, Weekly and Monthly.

Implement a daily task by extending DailyTask and implementing process().

class MyTask extends DailyTask {
 
    function process() {
      // implement your task here
    }
  }

You can also implement the index() method to overwrite which singleton classes are instantiated and processed. By default, all subclasses of the task are instantiated and used. For the DailyTask class, this means that an instance of each subclass of DailyTask will be created.

You can test your task from the command line by running:

cli-script.php /<MyTask>

Where <MyTask> is the classname of your task.

To perform all Daily tasks, run from the command line:

cli-script.php /DailyTask

Or, surf to URL http://mydomain.com/silverstripe/DailyTask. Within the cron (or similar scheduler) configuration, you can use one of these commands

You may also like to redirect output of these commands to /dev/null if you do not want to receive the emails from cron.

Note, do it similarly for WeeklyTask and MonthlyTask.

See API Documentation

 
scheduledtask.txt · Last modified: 2010/05/05 23:38 (external edit)

Please use comments for notes, tips and corrections about the described functionality.
Use the Silverstripe Forum to ask questions.

blog comments powered by Disqus
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Creative Commons LicenseSilverStripe Documentation by SilverStripe is licensed under a Creative Commons Attribution 3.0 New Zealand License.
Based on a work at doc.silverstripe.com
Recent changes RSS feed Driven by DokuWiki