Maintenance Queue

Table of Contents

Creating a Maintenance Script
Scheduling the Maintenance Script to Run
Storing Custom Data With Maintenance Queue Item
Scheduling the Queue Item
Retaining Client Context
Viewing the Maintenance Queue
Command-Line Tools
Queueing A Maintenance Task
Running a Maintenance Task Immediately
Processing Maintenance Queue

Frequently you will want a task to be performed immediately but it may take some time to execute. For example, if you want to process a credit card transaction it may take several seconds or minutes to process, so therefore this should be done in the background.

In order to achieve this, you can schedule a maintenance task. If Recite CMS has been correctly configured the maintenance queue will be processed every few minutes, so if you queue a task it will be performed in the near future.

There are two steps involved in doing this:

  1. Create a maintenance script by extending the Application_Maintenance_Abstract class.

  2. Schedule its execution by calling the queue() method on the queue item object.

Creating a Maintenance Script

To create a new maintenance you must either implement the Application_Maintenance_Interface interface, or extend the Application_Maintenance_Abstract class.

Note

It is recommended you extend the Application_Maintenance_Abstract class so you pick up any new functionality if it is added to the interface, and also so your existing scripts won't break if new methods are added to the interface.

The methods you must implement in your maintenance script are as follows:

  • public function __construct()

    The class constructor accepts no arguments. If you extend the Application_Maintenance_Abstract class you do not need to create this method. If you choose to implement this method be aware that this class may be instantiated even when not being run, so ensure the constructor does not cause any unexpected side-effects or have a high execution cost.

  • public function __toString()

    Returns: string

    This method should return a short descriptive string for the action the maintenance script performs. This is primarily used by the administrator when viewing the maintenance queue.

  • public function run(array $options)

    Argument 1: array. This argument holds an arbitrary list of parameters used for executing the maintenance script.

    Throws: Application_Maintenance_Exception

    This is the method that is run by the maintenance queue. If required, you can throw the specified exception in this function to indicate that an error has occurred. Doing so does not cause any side-effects (such as requeueing)

  • public function accept(array $options)

    Argument 1: array. This argument holds an arbitrary list of parameters used for executing the maintenance script.

    Returns: Boolean

    This method is used to decide whether or not the maintenance script can be queued. The arguments passed are identical to if the run() method was called. Return true if the script can be added to the queue or false if not.