Agenda

Agenda

new Agenda(config, cb)

Parameters:
Name Type Description
config Object

Agenda Config

cb function

Callback after Agenda has started and connected to mongo

Properties:
Name Type Description
_name Object

Name of the current Agenda queue

_processEvery Number
_defaultConcurrency Number
_maxConcurrency Number
_defaultLockLimit Number
_lockLimit Number
_definitions Object
_runningJobs Object
_lockedJobs Object
_jobQueue Object
_defaultLockLifetime Number
_sort Object
_indices Object
_isLockingOnTheFly Boolean
_jobsToLock Array
Source:

Methods

cancel(query) → {Promise.<Number>}

Cancels any jobs matching the passed MongoDB query, and removes them from the database.

Parameters:
Name Type Description
query Object

MongoDB query to use when cancelling

Source:

create(name, data) → {Job}

Given a name and some data, create a new job

Parameters:
Name Type Description
name String

name of job

data Object

data to set for job

Source:

database(url, collection, options, cb) → {exports}

Connect to the spec'd MongoDB server and database.

Parameters:
Name Type Description
url String

MongoDB server URI

collection String

name of collection to use. Defaults to agendaJobs

options Object

options for connecting

cb function

callback of MongoDB connection

Source:

dbInit(collection, cb) → {undefined}

Setup and initialize the collection used to manage Jobs.

Parameters:
Name Type Description
collection String

name or undefined for default 'agendaJobs'

cb function

called when the db is initialized

Source:

defaultConcurrency(num) → {exports}

Set the default concurrency for each job

Parameters:
Name Type Description
num Number

default concurrency

Source:

defaultLockLifetime(ms) → {Agenda}

Set the default lock time (in ms) Default is 10 * 60 * 1000 ms (10 minutes)

Parameters:
Name Type Description
ms Number

time in ms to set default lock

Source:

defaultLockLimit(num) → {Agenda}

Set default lock limit per job type

Parameters:
Name Type Description
num Number

Lock limit per job

Source:

define(name, options, processor) → {undefined}

Setup definition for job Method is used by consumers of lib to setup their functions

Parameters:
Name Type Description
name String

name of job

options Object

options for job to run

processor function

function to be called to run actual job

Source:

every(interval, names, dataopt, optionsopt) → {Promise}

Creates a scheduled job with given interval and name/names of the job to run

Parameters:
Name Type Attributes Description
interval String | Number

run every X interval

names String | Array.<String>

String or strings of jobs to schedule

data Object <optional>

data to run for job

options Object <optional>

options to run job for

Source:

(protected) findAndLockNextJob(jobName, definition)

Find and lock jobs

Parameters:
Name Type Description
jobName String

name of job to try to lock

definition Object

definition used to tell how job is run

Source:

jobs(query, sort, limit, number) → {Promise}

Finds all jobs matching 'query'

Parameters:
Name Type Description
query Object

object for MongoDB

sort Object

object for MongoDB

limit Number

number of documents to return from MongoDB

number Number

of documents to skip in MongoDB

Source:

locklimit(num) → {exports}

Set the default amount jobs that are allowed to be locked at one time (GLOBAL)

Parameters:
Name Type Description
num Number

Lock limit

Source:

maxConcurrency(num) → {exports}

Set the concurrency for jobs (globally), type does not matter

Parameters:
Name Type Description
num Number

max concurrency value

Source:

mongo(mdb, collection, cb) → {exports}

Build method used to add MongoDB connection details

Parameters:
Name Type Description
mdb MongoClient

instance of MongoClient to use

collection String

name collection we want to use ('agendaJobs')

cb function

called when MongoDB connection fails or passes

Source:

name(name) → {exports}

Set name of queue

Parameters:
Name Type Description
name String

name of agenda instance

Source:

now(name, data) → {Promise}

Create a job for this exact moment

Parameters:
Name Type Description
name String

name of job to schedule

data Object

data to pass to job

Source:

processEvery(time) → {exports}

Set the default process interval

Parameters:
Name Type Description
time Number | String

time to process, expressed in human interval

Source:

purge() → {Promise}

Removes all jobs from queue

Source:

saveJob(job) → {Promise}

Save the properties on a job to MongoDB

Parameters:
Name Type Description
job Job

job to save into MongoDB

Source:

schedule(when, names, data) → {Promise.<(Job|Array.<Job>)>}

Schedule a job or jobs at a specific time

Parameters:
Name Type Description
when String

when the job gets run

names Array.<String>

array of job names to run

data Object

data to send to job

Source:

sort(query) → {exports}

Set the sort query for finding next job Default is { nextRunAt: 1, priority: -1 }

Parameters:
Name Type Description
query Object

sort query object for MongoDB

Source:

start() → {Promise}

Starts processing jobs using processJobs() methods, storing an interval ID This method will only resolve if a db has been set up beforehand.

Source:

stop() → {Promise}

Clear the interval that processes the jobs

Source: