Registering Scheduled Tasks

Movable Type allows plugin developers to register tasks that should be executed outside the context of the main application. These tasks can be scheduled to occur at a designated frequency (specified in seconds).

The type of task that can be executed is not limited or bounded in any way.

sub init_registry {
    my $plugin = shift;
    $plugin->registry({
        tasks                    =>  {
            'MyCustomTask' => {
                label     => 'Do something every two minutes',
                frequency => 120,
                code      => \&execute_task,
            },
        },
    });
}

sub execute_task {
    # no input is passed to this callback
    # do something
}

When registering a scheduled task, the following properties must be specified:

  • label - the display name of the scheduled task as it will appear in the application (e.g. the Activity Log)
  • frequency - the minimum time (in seconds) between allowed execution of the task
  • code - a reference to a subroutine or code block that will be executed when the scheduled task is triggered

Turning on Scheduled Tasks

Scheduled tasks are managed and executed by a script that is shipped with Movable Type. This script called run-periodic-tasks and should be executed by cron (in Unix) or via Scheduled Tasks (in windows). You can run it as often as you like, but any tasks with a frequency setting will be skipped if the last execution of that task falls within that window of time.

This page was last updated on 2008-07-11, 14:47.  

Leave a note

Have a question, please use the MT Forums. Notes sumbitted here should pertain to tips & hints regarding documentation.