Skip to content
Kiernan Tim McGowan edited this page Sep 30, 2013 · 2 revisions

Manager

The manager is the central logic to forerunner. It will respond to connecting workers and use the given queue and store objects to process any jobs. While it is not possible to replace the central logic, how the manager reacts to different jobs can be extended through the use of plugins.

Example Usage

var forerunner = require('forerunner').forerunner;

// set up your queue and store
var queue = require('my-awesome-queue');

// register any plugins
var plugin = require('my-sweet-plugin');
forerunner.plugin(plugin);

// start the manager
var opts = {
  queue: queue
};
forerunner.start(opts);

// assign jobs!
forerunner.assignJob('job_type', {foo: bar, cat: dog});

Methods

start(opts)

Starts the forerunner with a set of options. This is required to be called before jobs can be processed. See the configuration page for details.

registerPlugin(plugin)

Registers a plugin with forerunner. Plugins allow for extended functionality in reaction to job state. See the plugin page for details on writing your own.

assignJob(jobType, rawData, callback(err, jobId, jobData))

Creates a new job of jobType with the input rawData. Attempts to first create the job in the store and then add it to the queue. If either of these operations fail, the job will not be processed and the function will callback with an error. Otherwise, the callback will send back the id of the job created and the payload that was created by the store.

Job State

In order to react to what is going on in the job queue functions can be added to listen to various events that happen to a job during processing. These functions are purely reactionary and are unable to alter, delay, or stop a job as it is processing. The jobType that the function is assigned to can either be one jobType or an array of jobTypes.

onCreated(jobType, fn(jobId, jobData))

Called when a job has been created in the store and added to the queue.

onStaged(jobType, fn(jobId, jobData))

Called when a job has been sent off to the worker pool.

onProgress(jobType, fn(jobId, progress))

Called when a job has emitted a progress event from the worker pool.

onFailed(jobType, fn(jobId, message))

Called when a job has failed more than the set max_fail_count.

onComplete(jobType, fn(jobId, jobResult))

Called when a job has completed.

Clone this wiki locally