jobs

module:jobs

Description:
  • Job queue processor

    When launched with jobs-workers parameter equal or greater than 0, the server spawns a number of workers which subscribe to configured job queues or the default queue and listen for messages.

    A job message is an object that defines what method from which module to run with the options as the first argument and a callback as the second.

    Multiple job queues can be defined and processed at the same time.

    By default local and worker queues are always created and ready to be used, jobs sent to local always run inside the local process but jobs sent to worker queue will be run in a worker.

    A job can be in the following formats:

    "module.method" { job: { "module.method": {}, .... } }

    any task in string format "module.method" will be converted into { "module.method: {} } automatically

Methods

(static) submitJob(jobspec, optionsopt, {int{})

Description:
  • Submit a job for execution, it will be saved in a queue and will be picked up later and executed. The queue and the way how it will be executed depends on the configured queue. See isJob for the format of the job objects.

Parameters:
Name Type Attributes Description
jobspec object

an object with jobs to run

options object <optional>
Properties
Name Type Attributes Description
uniqueTtl int <optional>

if greater than zero it defines number of milliseconds for this job to stay in the queue or run, it creates a global lock using the job object as the hash key, no other job can be run until the ttl expires or the job finished, non unique jobs will be kept in the queue and repeated later according to the visibilityTimeout setting.

uniqueKey int <optional>

can define an alternative unique key for this job for cases when different jobs must be run sequentially

uniqueKeep int <optional>

if true then keep the unique lock after the jobs finished, otherwise it is cleared

uniqueDrop int <optional>

if true will make non-unique jobs to be silently dropped instead of keeping them in the queue

logger int <optional>

defines the logger level which will be used to log when the job is finished, default is debug

maxRuntime int <optional>

defines max number of seconds this job can run, if not specified then the queue default is used

uniqueOnce int <optional>

if true than the visibility timeout is not kept alive while the job is running

noWait int <optional>

will run the job and delete it from the queue immediately, not at the end, for one-off jobs

noWaitTimeout int <optional>

number of seconds before deleting the job for one-off jobs but taking into account the uniqueKey and visibility timeout giving time to check for uniqueness and exit, can be used regardless of the noWait flag

noVisibility int <optional>

will always delete messages after processing, ignore 600 errors as well

visibilityTimeout int <optional>

custom timeout for how long to keep this job invisible, overrides the default timeout

retryVisibilityTimeout int <optional>

an object with custom timeouts for how long to keep this job invisible by error status which results in keeping tasks in the queue for retry

stopOnError int <optional>

will stop tasks processing on first error, otherwise all errors will be just logged. Errors with status >= 600 will stop the job regardless of this flag

startTime int <optional>

job must start only after this date, if started sooner it will be put back into the queue

{int{}

[options.endTime] - job must not start after this date

options.delay int <optional>

is only supported by SQS currently, it delays the job execution for the specified amount of ms

options.dedup_ttl int <optional>

if set it defines number of ms to keep track of duplicate messages, it tries to preserver only-once behaviour. To make some queue to automatically use dedup mode it can be set in the queue options: -queue[-NAME]-options-dedup_ttl 86400000. Note: uniqueTtl settings take precedence and if present dedup is ignored.