The Agenda Unit


exports:  AgendaUnit

class AgendaUnit

extends:  libflitter/Unit

Initializes the Agenda scheduler for Flitter. Loads job definitions from the specified directory of classes which extend flitter-agenda/Job and registers them with the scheduler. Starts the scheduler. This establishes the Agenda context and calls the next function under it.


type:  String

Fully-qualified path to the folder where the job definition class files are stored.

constructor(String directory = './app/jobs')

returns:  this

Initializes the class. Resolves the provided directory and stores it in

go(express app, function next)

returns:  undefined

Initializes the unit. Creates a new Agenda scheduler and connects it to the MongoDB server. Creates the _flit.sched object, then calls this.load_jobs() and passes it the scheduler and the next function in the stack.

load_jobs(agenda sched, function next)

returns:  undefined

Loads the job definition classes from the files in that end with the .job.js extension, recursively. Each job is assigned a name which is parsed from the file name and sub-directory. flitter-agenda follows the Flitter convention for sub-directory naming -- sub-directories are delineated with a : character. For example, the file app/jobs/auth/CleanUsers.job.js would be named auth:CleanUsers. These job classes are initialized and registered with the scheduler. Finally, this.daemon() is called and passed the next function.

daemon(function next)

returns:  undefined

Starts the scheduler. Once that has completed, it calls the next function from within that context.


returns:  Object

Returns an Object describing the services, templates, and directories provided by this unit. They are as follows:

Type Key Value Notes
Service Name name "flitter-agenda" The name of the service. This is added to the array so other units can check for this unit.
Directory The fully-qualified path of the job definition files. This is added to the _flit.directories store so other units can access it.
Template templates.job Object Template that creates new job definition file in

Agenda Context

Guarantees that the job definitions have been loaded and registered with the scheduler and that the scheduler has been started.


type:  Object

Holds the variables and functions provided by this unit.


type:  agenda

Instance of the Agenda scheduler. The scheduler has already been started via the start() method. This can be used to schedule and manage jobs as per the Agenda docs.

type:  Object

Set of key-value pairs such that the value is an instance of flitter-agenda/Job, and the value is the name of the job. Job names are parsed from file names and follow the Flitter convention for sub-directory naming. That is, sub-directories should be delineated with a : character. For example, the job defined in the file app/jobs/auth/CleanUsers.job.js would be named auth:CleanUsers.

No Comments
Back to top