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

MongoDB query to use when cancelling

Source:

cancel(query)

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

Parameters:
Name Type Description
query

MongoDB query to use when cancelling

Source:

close(optionopt)

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:
Name Type Attributes Description
option Object <optional>

Force close, emitting no events

Source:

close(optionopt)

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:
Name Type Attributes Description
option Object <optional>

Force close, emitting no events

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:

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, collectionopt, optionsopt, cbopt)

Connect to the spec'd MongoDB server and database.

NOTE: If url includes auth details then options must specify: { 'uri_decode_auth': true }. This does Auth on the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB, then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in the constructor or use Agenda.mongo().

Parameters:
Name Type Attributes Description
url

MongoDB server URI

collection <optional>

name of collection to use. Defaults to agendaJobs

options <optional>

options for connecting

cb <optional>

callback of MongoDB connection

Source:

database(url, collectionopt, optionsopt, cbopt)

Connect to the spec'd MongoDB server and database.

NOTE: If url includes auth details then options must specify: { 'uri_decode_auth': true }. This does Auth on the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB, then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in the constructor or use Agenda.mongo().

Parameters:
Name Type Attributes Description
url

MongoDB server URI

collection <optional>

name of collection to use. Defaults to agendaJobs

options <optional>

options for connecting

cb <optional>

callback of MongoDB connection

Source:

dbInit(collection, cbopt)

Setup and initialize the collection used to manage Jobs.

Parameters:
Name Type Attributes Description
collection

name or undefined for default 'agendaJobs'

cb <optional>

called when the db is initialized

Source:

dbInit(collection, cbopt)

Setup and initialize the collection used to manage Jobs.

Parameters:
Name Type Attributes Description
collection

name or undefined for default 'agendaJobs'

cb <optional>

called when the db is initialized

Source:

defaultConcurrency(concurrency)

Set the default concurrency for each job

Parameters:
Name Type Description
concurrency

default concurrency

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:

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:

defaultLockLimit(num) → {Agenda}

Set default lock limit per job type

Parameters:
Name Type Description
num Number

Lock limit per job

Source:

define(name, options, processoropt)

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

Parameters:
Name Type Attributes Description
name

name of job

options

options for job to run

processor <optional>

function to be called to run actual job

Source:

define(name, options, processoropt)

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

Parameters:
Name Type Attributes Description
name

name of job

options

options for job to run

processor <optional>

function to be called to run actual job

Source:

disable(query) → {Promise.<number>}

Disables any jobs matching the passed MongoDB query by setting the disabled flag to true

Parameters:
Name Type Description
query

MongoDB query to use when enabling

Source:

disable(query) → {Promise.<number>}

Disables any jobs matching the passed MongoDB query by setting the disabled flag to true

Parameters:
Name Type Description
query

MongoDB query to use when enabling

Source:

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

Enables any jobs matching the passed MongoDB query by setting the disabled flag to false

Parameters:
Name Type Description
query

MongoDB query to use when enabling

Source:

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

Enables any jobs matching the passed MongoDB query by setting the disabled flag to false

Parameters:
Name Type Description
query

MongoDB query to use when enabling

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:

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:

(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(queryopt, sortopt, limitopt, numberopt)

Finds all jobs matching 'query'

Parameters:
Name Type Attributes Description
query <optional>

object for MongoDB

sort <optional>

object for MongoDB

limit <optional>

number of documents to return from MongoDB

number <optional>

of documents to skip in MongoDB

Source:

jobs(queryopt, sortopt, limitopt, numberopt)

Finds all jobs matching 'query'

Parameters:
Name Type Attributes Description
query <optional>

object for MongoDB

sort <optional>

object for MongoDB

limit <optional>

number of documents to return from MongoDB

number <optional>

of documents to skip in MongoDB

Source:

locklimit(limit)

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

Parameters:
Name Type Description
limit

num Lock limit

Source:

locklimit(limit)

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

Parameters:
Name Type Description
limit

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:

maxConcurrency(concurrency)

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

Parameters:
Name Type Description
concurrency

max concurrency value

Source:

mongo(mdb, collectionopt, cbopt)

Build method used to add MongoDB connection details

Parameters:
Name Type Attributes Description
mdb

instance of MongoClient to use

collection <optional>

name collection we want to use ('agendaJobs')

cb <optional>

called when MongoDB connection fails or passes

Source:

mongo(mdb, collectionopt, cbopt)

Build method used to add MongoDB connection details

Parameters:
Name Type Attributes Description
mdb

instance of MongoClient to use

collection <optional>

name collection we want to use ('agendaJobs')

cb <optional>

called when MongoDB connection fails or passes

Source:

name(name)

Set name of queue

Parameters:
Name Type Description
name

name of agenda instance

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:

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:

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:

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:

saveJob(job)

Save the properties on a job to MongoDB

Parameters:
Name Type Description
job

job to save into MongoDB

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:

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:

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:

stop()

Clear the interval that processes the jobs

Source:

Agenda

new Agenda(config, cb)

Constructs a new Agenda object.

Parameters:
Name Type Description
config

Optional configuration to initialize the Agenda.

cb

Optional callback called with the MongoDB collection.

Source:

Methods

cancel(query)

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

Parameters:
Name Type Description
query

MongoDB query to use when cancelling

Source:

cancel(query)

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

Parameters:
Name Type Description
query

MongoDB query to use when cancelling

Source:

close(optionopt)

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:
Name Type Attributes Description
option Object <optional>

Force close, emitting no events

Source:

close(optionopt)

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:
Name Type Attributes Description
option Object <optional>

Force close, emitting no events

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:

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, collectionopt, optionsopt, cbopt)

Connect to the spec'd MongoDB server and database.

NOTE: If url includes auth details then options must specify: { 'uri_decode_auth': true }. This does Auth on the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB, then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in the constructor or use Agenda.mongo().

Parameters:
Name Type Attributes Description
url

MongoDB server URI

collection <optional>

name of collection to use. Defaults to agendaJobs

options <optional>

options for connecting

cb <optional>

callback of MongoDB connection

Source:

database(url, collectionopt, optionsopt, cbopt)

Connect to the spec'd MongoDB server and database.

NOTE: If url includes auth details then options must specify: { 'uri_decode_auth': true }. This does Auth on the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB, then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in the constructor or use Agenda.mongo().

Parameters:
Name Type Attributes Description
url

MongoDB server URI

collection <optional>

name of collection to use. Defaults to agendaJobs

options <optional>

options for connecting

cb <optional>

callback of MongoDB connection

Source:

dbInit(collection, cbopt)

Setup and initialize the collection used to manage Jobs.

Parameters:
Name Type Attributes Description
collection

name or undefined for default 'agendaJobs'

cb <optional>

called when the db is initialized

Source:

dbInit(collection, cbopt)

Setup and initialize the collection used to manage Jobs.

Parameters:
Name Type Attributes Description
collection

name or undefined for default 'agendaJobs'

cb <optional>

called when the db is initialized

Source:

defaultConcurrency(concurrency)

Set the default concurrency for each job

Parameters:
Name Type Description
concurrency

default concurrency

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:

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:

defaultLockLimit(num) → {Agenda}

Set default lock limit per job type

Parameters:
Name Type Description
num Number

Lock limit per job

Source:

define(name, options, processoropt)

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

Parameters:
Name Type Attributes Description
name

name of job

options

options for job to run

processor <optional>

function to be called to run actual job

Source:

define(name, options, processoropt)

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

Parameters:
Name Type Attributes Description
name

name of job

options

options for job to run

processor <optional>

function to be called to run actual job

Source:

disable(query) → {Promise.<number>}

Disables any jobs matching the passed MongoDB query by setting the disabled flag to true

Parameters:
Name Type Description
query

MongoDB query to use when enabling

Source:

disable(query) → {Promise.<number>}

Disables any jobs matching the passed MongoDB query by setting the disabled flag to true

Parameters:
Name Type Description
query

MongoDB query to use when enabling

Source:

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

Enables any jobs matching the passed MongoDB query by setting the disabled flag to false

Parameters:
Name Type Description
query

MongoDB query to use when enabling

Source:

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

Enables any jobs matching the passed MongoDB query by setting the disabled flag to false

Parameters:
Name Type Description
query

MongoDB query to use when enabling

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:

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:

(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(queryopt, sortopt, limitopt, numberopt)

Finds all jobs matching 'query'

Parameters:
Name Type Attributes Description
query <optional>

object for MongoDB

sort <optional>

object for MongoDB

limit <optional>

number of documents to return from MongoDB

number <optional>

of documents to skip in MongoDB

Source:

jobs(queryopt, sortopt, limitopt, numberopt)

Finds all jobs matching 'query'

Parameters:
Name Type Attributes Description
query <optional>

object for MongoDB

sort <optional>

object for MongoDB

limit <optional>

number of documents to return from MongoDB

number <optional>

of documents to skip in MongoDB

Source:

locklimit(limit)

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

Parameters:
Name Type Description
limit

num Lock limit

Source:

locklimit(limit)

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

Parameters:
Name Type Description
limit

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:

maxConcurrency(concurrency)

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

Parameters:
Name Type Description
concurrency

max concurrency value

Source:

mongo(mdb, collectionopt, cbopt)

Build method used to add MongoDB connection details

Parameters:
Name Type Attributes Description
mdb

instance of MongoClient to use

collection <optional>

name collection we want to use ('agendaJobs')

cb <optional>

called when MongoDB connection fails or passes

Source:

mongo(mdb, collectionopt, cbopt)

Build method used to add MongoDB connection details

Parameters:
Name Type Attributes Description
mdb

instance of MongoClient to use

collection <optional>

name collection we want to use ('agendaJobs')

cb <optional>

called when MongoDB connection fails or passes

Source:

name(name)

Set name of queue

Parameters:
Name Type Description
name

name of agenda instance

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:

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:

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:

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:

saveJob(job)

Save the properties on a job to MongoDB

Parameters:
Name Type Description
job

job to save into MongoDB

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:

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:

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:

stop()

Clear the interval that processes the jobs

Source:

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

MongoDB query to use when cancelling

Source:

cancel(query)

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

Parameters:
Name Type Description
query

MongoDB query to use when cancelling

Source:

close(optionopt)

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:
Name Type Attributes Description
option Object <optional>

Force close, emitting no events

Source:

close(optionopt)

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:
Name Type Attributes Description
option Object <optional>

Force close, emitting no events

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:

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, collectionopt, optionsopt, cbopt)

Connect to the spec'd MongoDB server and database.

NOTE: If url includes auth details then options must specify: { 'uri_decode_auth': true }. This does Auth on the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB, then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in the constructor or use Agenda.mongo().

Parameters:
Name Type Attributes Description
url

MongoDB server URI

collection <optional>

name of collection to use. Defaults to agendaJobs

options <optional>

options for connecting

cb <optional>

callback of MongoDB connection

Source:

database(url, collectionopt, optionsopt, cbopt)

Connect to the spec'd MongoDB server and database.

NOTE: If url includes auth details then options must specify: { 'uri_decode_auth': true }. This does Auth on the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB, then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in the constructor or use Agenda.mongo().

Parameters:
Name Type Attributes Description
url

MongoDB server URI

collection <optional>

name of collection to use. Defaults to agendaJobs

options <optional>

options for connecting

cb <optional>

callback of MongoDB connection

Source:

dbInit(collection, cbopt)

Setup and initialize the collection used to manage Jobs.

Parameters:
Name Type Attributes Description
collection

name or undefined for default 'agendaJobs'

cb <optional>

called when the db is initialized

Source:

dbInit(collection, cbopt)

Setup and initialize the collection used to manage Jobs.

Parameters:
Name Type Attributes Description
collection

name or undefined for default 'agendaJobs'

cb <optional>

called when the db is initialized

Source:

defaultConcurrency(concurrency)

Set the default concurrency for each job

Parameters:
Name Type Description
concurrency

default concurrency

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:

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:

defaultLockLimit(num) → {Agenda}

Set default lock limit per job type

Parameters:
Name Type Description
num Number

Lock limit per job

Source:

define(name, options, processoropt)

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

Parameters:
Name Type Attributes Description
name

name of job

options

options for job to run

processor <optional>

function to be called to run actual job

Source:

define(name, options, processoropt)

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

Parameters:
Name Type Attributes Description
name

name of job

options

options for job to run

processor <optional>

function to be called to run actual job

Source:

disable(query) → {Promise.<number>}

Disables any jobs matching the passed MongoDB query by setting the disabled flag to true

Parameters:
Name Type Description
query

MongoDB query to use when enabling

Source:

disable(query) → {Promise.<number>}

Disables any jobs matching the passed MongoDB query by setting the disabled flag to true

Parameters:
Name Type Description
query

MongoDB query to use when enabling

Source:

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

Enables any jobs matching the passed MongoDB query by setting the disabled flag to false

Parameters:
Name Type Description
query

MongoDB query to use when enabling

Source:

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

Enables any jobs matching the passed MongoDB query by setting the disabled flag to false

Parameters:
Name Type Description
query

MongoDB query to use when enabling

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:

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:

(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(queryopt, sortopt, limitopt, numberopt)

Finds all jobs matching 'query'

Parameters:
Name Type Attributes Description
query <optional>

object for MongoDB

sort <optional>

object for MongoDB

limit <optional>

number of documents to return from MongoDB

number <optional>

of documents to skip in MongoDB

Source:

jobs(queryopt, sortopt, limitopt, numberopt)

Finds all jobs matching 'query'

Parameters:
Name Type Attributes Description
query <optional>

object for MongoDB

sort <optional>

object for MongoDB

limit <optional>

number of documents to return from MongoDB

number <optional>

of documents to skip in MongoDB

Source:

locklimit(limit)

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

Parameters:
Name Type Description
limit

num Lock limit

Source:

locklimit(limit)

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

Parameters:
Name Type Description
limit

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:

maxConcurrency(concurrency)

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

Parameters:
Name Type Description
concurrency

max concurrency value

Source:

mongo(mdb, collectionopt, cbopt)

Build method used to add MongoDB connection details

Parameters:
Name Type Attributes Description
mdb

instance of MongoClient to use

collection <optional>

name collection we want to use ('agendaJobs')

cb <optional>

called when MongoDB connection fails or passes

Source:

mongo(mdb, collectionopt, cbopt)

Build method used to add MongoDB connection details

Parameters:
Name Type Attributes Description
mdb

instance of MongoClient to use

collection <optional>

name collection we want to use ('agendaJobs')

cb <optional>

called when MongoDB connection fails or passes

Source:

name(name)

Set name of queue

Parameters:
Name Type Description
name

name of agenda instance

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:

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:

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:

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:

saveJob(job)

Save the properties on a job to MongoDB

Parameters:
Name Type Description
job

job to save into MongoDB

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:

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:

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:

stop()

Clear the interval that processes the jobs

Source:

Agenda

new Agenda(config, cb)

Constructs a new Agenda object.

Parameters:
Name Type Description
config

Optional configuration to initialize the Agenda.

cb

Optional callback called with the MongoDB collection.

Source:

Methods

cancel(query)

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

Parameters:
Name Type Description
query

MongoDB query to use when cancelling

Source:

cancel(query)

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

Parameters:
Name Type Description
query

MongoDB query to use when cancelling

Source:

close(optionopt)

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:
Name Type Attributes Description
option Object <optional>

Force close, emitting no events

Source:

close(optionopt)

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:
Name Type Attributes Description
option Object <optional>

Force close, emitting no events

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:

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, collectionopt, optionsopt, cbopt)

Connect to the spec'd MongoDB server and database.

NOTE: If url includes auth details then options must specify: { 'uri_decode_auth': true }. This does Auth on the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB, then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in the constructor or use Agenda.mongo().

Parameters:
Name Type Attributes Description
url

MongoDB server URI

collection <optional>

name of collection to use. Defaults to agendaJobs

options <optional>

options for connecting

cb <optional>

callback of MongoDB connection

Source:

database(url, collectionopt, optionsopt, cbopt)

Connect to the spec'd MongoDB server and database.

NOTE: If url includes auth details then options must specify: { 'uri_decode_auth': true }. This does Auth on the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB, then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in the constructor or use Agenda.mongo().

Parameters:
Name Type Attributes Description
url

MongoDB server URI

collection <optional>

name of collection to use. Defaults to agendaJobs

options <optional>

options for connecting

cb <optional>

callback of MongoDB connection

Source:

dbInit(collection, cbopt)

Setup and initialize the collection used to manage Jobs.

Parameters:
Name Type Attributes Description
collection

name or undefined for default 'agendaJobs'

cb <optional>

called when the db is initialized

Source:

dbInit(collection, cbopt)

Setup and initialize the collection used to manage Jobs.

Parameters:
Name Type Attributes Description
collection

name or undefined for default 'agendaJobs'

cb <optional>

called when the db is initialized

Source:

defaultConcurrency(concurrency)

Set the default concurrency for each job

Parameters:
Name Type Description
concurrency

default concurrency

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:

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:

defaultLockLimit(num) → {Agenda}

Set default lock limit per job type

Parameters:
Name Type Description
num Number

Lock limit per job

Source:

define(name, options, processoropt)

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

Parameters:
Name Type Attributes Description
name

name of job

options

options for job to run

processor <optional>

function to be called to run actual job

Source:

define(name, options, processoropt)

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

Parameters:
Name Type Attributes Description
name

name of job

options

options for job to run

processor <optional>

function to be called to run actual job

Source:

disable(query) → {Promise.<number>}

Disables any jobs matching the passed MongoDB query by setting the disabled flag to true

Parameters:
Name Type Description
query

MongoDB query to use when enabling

Source:

disable(query) → {Promise.<number>}

Disables any jobs matching the passed MongoDB query by setting the disabled flag to true

Parameters:
Name Type Description
query

MongoDB query to use when enabling

Source:

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

Enables any jobs matching the passed MongoDB query by setting the disabled flag to false

Parameters:
Name Type Description
query

MongoDB query to use when enabling

Source:

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

Enables any jobs matching the passed MongoDB query by setting the disabled flag to false

Parameters:
Name Type Description
query

MongoDB query to use when enabling

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:

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:

(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(queryopt, sortopt, limitopt, numberopt)

Finds all jobs matching 'query'

Parameters:
Name Type Attributes Description
query <optional>

object for MongoDB

sort <optional>

object for MongoDB

limit <optional>

number of documents to return from MongoDB

number <optional>

of documents to skip in MongoDB

Source:

jobs(queryopt, sortopt, limitopt, numberopt)

Finds all jobs matching 'query'

Parameters:
Name Type Attributes Description
query <optional>

object for MongoDB

sort <optional>

object for MongoDB

limit <optional>

number of documents to return from MongoDB

number <optional>

of documents to skip in MongoDB

Source:

locklimit(limit)

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

Parameters:
Name Type Description
limit

num Lock limit

Source:

locklimit(limit)

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

Parameters:
Name Type Description
limit

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:

maxConcurrency(concurrency)

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

Parameters:
Name Type Description
concurrency

max concurrency value

Source:

mongo(mdb, collectionopt, cbopt)

Build method used to add MongoDB connection details

Parameters:
Name Type Attributes Description
mdb

instance of MongoClient to use

collection <optional>

name collection we want to use ('agendaJobs')

cb <optional>

called when MongoDB connection fails or passes

Source:

mongo(mdb, collectionopt, cbopt)

Build method used to add MongoDB connection details

Parameters:
Name Type Attributes Description
mdb

instance of MongoClient to use

collection <optional>

name collection we want to use ('agendaJobs')

cb <optional>

called when MongoDB connection fails or passes

Source:

name(name)

Set name of queue

Parameters:
Name Type Description
name

name of agenda instance

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:

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:

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:

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:

saveJob(job)

Save the properties on a job to MongoDB

Parameters:
Name Type Description
job

job to save into MongoDB

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:

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:

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:

stop()

Clear the interval that processes the jobs

Source: