Not a developer? Go to MovableType.com

Documentation

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.

Tasks are run via one of two ways:

  • through the use of the run-periodic-tasks.pl framework
  • through the web interface

Note: For the last case above it is important to note that scheduled tasks will only be executed if a user accesses the administrative interface at a time when a task is due to be executed. One common tip recommended by the community is to subscribe to your system’s Activity Feed in Google Reader. This will result in a third party hitting the main Movable Type application, and by consequence trigger any background tasks that are due to be run.

To create a task, you will first need to edit your config.yaml file and register your task according to the example below.

name: Example Plugin for Movable Type
id: Example
description: This plugin is an example plugin for Movable Type.
version: 1.0
tasks:
    MyCustomTask:
        label: Do something every two minutes
        frequency: 120
        code: $Example::Example::Plugin::exec_task

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

  • 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

Task Handler

Once the task has been registered you will need to edit your Plugin.pm file and add a task handler. This task handler will take no input. It is just a static method that will be invoked by Movable Type.

package Example::Plugin;
use strict;

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

1; # Every module must return true
Back

Leave a Comment