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

true if 'lockingOnTheFly' is currently running. Prevent concurrent execution of this method.

_isJobQueueFilling Map

A map of jobQueues and if the 'jobQueueFilling' method is currently running for a given map. 'lockingOnTheFly' and 'jobQueueFilling' should not run concurrently for the same jobQueue. It can cause that lock limits aren't honored.

_jobsToLock Array
Source:

Methods

cancel(query)

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:

close()

Close the db and it's underlying connections Only works if agenda was instantiated without preconfigured mongoDb instance. If the mongoDb instance was supplied during instantiation or via agenda.mongo, this function will do nothing and return agenda anyway.

Parameters:
Type Description
Source:

create(name, data)

Given a name and some data, create a new job

Parameters:
Name Type Description
name

name of job

data

data to set for job

Source:

database(url, collection, options)

Connect to the spec'd MongoDB server and database.

Parameters:
Name Type Description
url

MongoDB server URI

collection

name of collection to use. Defaults to agendaJobs

options

options for connecting

Source:

dbInit(collection, cb)

Setup and initialize the collection used to manage Jobs.

Parameters:
Name Type Description
collection

name or undefined for default 'agendaJobs'

cb

called when the db is initialized

Source:

defaultConcurrency(concurrency)

Set the default concurrency for each job

Parameters:
Name Type Description
concurrency

default concurrency

Source:

defaultLockLifetime(ms)

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)

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

Parameters:
Name Type Description
name

name of job

options

options for job to run

processor

function to be called to run actual job

Source:

every(interval, names, data, options)

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

Parameters:
Name Type Description
interval

run every X interval

names

String or strings of jobs to schedule

data

data to run for job

options

options to run job for

Source:

(protected) findAndLockNextJob(jobName, definition)

Find and lock jobs

Parameters:
Name Type Description
jobName

name of job to try to lock

definition

definition used to tell how job is run

Source:

jobs(query, sort, limit, number)

Finds all jobs matching 'query'

Parameters:
Name Type Description
query

object for MongoDB

sort

object for MongoDB

limit

number of documents to return from MongoDB

number

of documents to skip in MongoDB

Source:

locklimit(num)

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

Parameters:
Name Type Description
num

Lock limit

Source:

maxConcurrency(concurrency)

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

Parameters:
Name Type Description
concurrency

max concurrency value

Source:

mongo(mdb, collection, cb)

Build method used to add MongoDB connection details

Parameters:
Name Type Description
mdb

instance of MongoClient to use

collection

name collection we want to use ('agendaJobs')

cb

called when MongoDB connection fails or passes

Source:

name(name)

Set name of queue

Parameters:
Name Type Description
name

name of agenda instance

Source:

now(name, data)

Create a job for this exact moment

Parameters:
Name Type Description
name

name of job to schedule

data

data to pass to job

Source:

processEvery(time)

Set the default process interval

Parameters:
Name Type Description
time

time to process, expressed in human interval

Source:

purge()

Removes all jobs from queue

Source:

saveJob(job)

Save the properties on a job to MongoDB

Parameters:
Name Type Description
job

job to save into MongoDB

Source:

schedule(when, names, data)

Schedule a job or jobs at a specific time

Parameters:
Name Type Description
when

when the job gets run

names

array of job names to run

data

data to send to job

Source:

sort(query)

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

Parameters:
Name Type Description
query

sort query object for MongoDB

Source:

start()

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()

Clear the interval that processes the jobs

Source: