AgendaUnit

flitter-agenda/AgendaUnit~ AgendaUnit

Unit service to for the Agenda scheduler. On load, it registers jobs from the configured directory (usually './app/jobs') and starts the job queue.


Constructor

new AgendaUnit(directory)

Initialize the class. Resolves and stores the directory containing the job definition files.

Parameters:
Name Type Default Description
directory string ./app/jobs

Directory containing the job definition files.

Extends

Members

(static) name

Get the name of this service: 'jobs'

(static) services

Define the services required by this unit.

(private) _di_allow_defer :boolean

If true, the injector will defer the class if the class requests any services that the container is missing. These services are filled in later and added to the prototype and any instances. True by default.

Type:
  • boolean

(private) _di_deferred_instances :Array.<module:flitter-di/src/Injectable~Injectable>

Collection of instances of this class that need to have the deferred service instances injected into them when the deferred services are finally provided.

(private) _di_deferred_services :Array.<string>

List of services that were deferred and not provided at the time of injection.

Type:
  • Array.<string>

canonical_item :string

Name of the unit's canonical item - 'job'

Type:
  • string

canonical_items :object

Mapping of canonical names to instances for this item.

Type:
  • object

directory :Promise.<void>|Promise.<string>

The root directory for this canonical resource's files.

Type:
  • Promise.<void> | Promise.<string>

suffix :string

File suffix for the unit's files - '.job.js'

Type:
  • string

Methods

(async) cleanup(app) → {Promise.<void>}

Clean up the resources managed by this unit. Stops the scheduler.

Parameters:
Name Type Description
app module:libflitter/app/FlitterApp~FlitterApp

the Flitter app

Returns:
Type
Promise.<void>

directories() → {object}

Get the directories provided by this unit.

Returns:
Type
object

get(name) → {object}

Resolve an unqualified canonical name to a registered canonical item.

Parameters:
Name Type Description
name string
Returns:
Type
object

(async) go(app) → {Promise.<void>}

Initialize the jobs service. Creates a new Agenda scheduler and registers the jobs in the canonical directory for this unit.

Parameters:
Name Type Description
app module:libflitter/app/FlitterApp~FlitterApp

the Flitter app

Returns:
Type
Promise.<void>

(async) init_canonical_file(app, name, instance) → {Promise.<module:flitter-agenda/Job~Job>}

Initialize a single canonical file loaded by the unit. Defines a job in the scheduler using the exec method on the job's class definition.

Parameters:
Name Type Description
app module:libflitter/app/FlitterApp~FlitterApp

the Flitter app

name string

the unqualified canonical name of the file

instance module:flitter-agenda/Job~Job

include from the file; should be a class definition of the Job

Returns:
Type
Promise.<module:flitter-agenda/Job~Job>

name() → {String}

Get the name of the unit. Should be a lowercase, alphanum/dash/underscore string.

Returns:
Type
String

status(setopt) → {string}

Get or set the unit's current status.

Parameters:
Name Type Attributes Description
set string <optional>

if provided, set the status of the unit

Returns:
  • current status of the unit
Type
string

templates() → {object}

Returns the templates managed by the AgendaUnit. Provides the 'job' template.

Returns:
Type
object