Scheduling the Maintenance Script to Run

In order the schedule the maintenance script you've created you use the Application_Maintenance_QueueItem class. Create an instance of this class then call its queue() method.

When instantiating Application_Maintenance_QueueItem, pass the name of your maintenance script class as the only argument to the constructor.

Example 5.1. Queueing up a maintenance script

<?php
    $queueItem = new Application_Maintenance_QueueItem('Your_Maintenance_Class');
    $queueItem->queue();
?>

Storing Custom Data With Maintenance Queue Item

Often you will want to store data with your maintenance queue item. This is data that is passed to the run() method of your maintenance script.

To store data with the queue item use the setParam() method. The first argument to this method is the name of the parameter while the second is the corresponding value.

Example 5.2. Storing custom data with maintenance queue item

<?php
    $queueItem = new Application_Maintenance_QueueItem('Your_Maintenance_Class');
    $queueItem->setParam('foo', 'bar')
              ->queue();
?>

Scheduling the Queue Item

You can decide when the execute the queue item by calling the setCreatedTimestamp() method. This method accepts as its only argument a UNIX timestamp which indicates when the queue item should be run. You can generate this value with PHP's mktime().

Example 5.3. Scheduling Queue Item Execution For January 1, 2011.

<?php
    $queueItem = new Application_Maintenance_QueueItem('Your_Maintenance_Class');
    $queueItem->setCreatedTimestamp(mktime(0, 0, 0, 1, 1, 2011))
              ->queue();
?>

Note

If you specify a time in the past, the queue item will be executed next time the queue is processed.