Skip to content

DevGuide ScheduledTasks

Violet edited this page Oct 28, 2010 · 1 revision

MDG: Setting Up Scheduled Tasks

Melody 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 Melody 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 Melody
id: Example
description: This plugin is an example plugin for Melody.
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 Melody.

package Example::Plugin;
use strict;

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

1; # Every module must return true

Turning on Scheduled Tasks

Scheduled tasks are managed and executed by a script that is shipped with Melody. 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.

Continue Reading

 


Questions, comments, can't find something? Let us know at our community outpost on Get Satisfaction.

Credits

  • Author: Byrne Reese
  • Edited by:
Clone this wiki locally