Is this middleware applied to all tasks?
Unique name for the middleware.
Called after a task using this middleware is enqueued.
Called after the task runs.
Called before a task using this middleware is enqueued.
Called berore the task runs. Has access to all params, before sanitization. Can modify the data object for use in tasks.
Module load order. Defaults to api.config.general.defaultMiddlewarePriority.
Generated using TypeDoc
An example middleware
const middleware = { name: 'timer', global: true, priority: 90, preProcessor: async function () { const worker = this.worker worker.startTime = process.hrtime() }, postProcessor: async function () { const worker = this.worker const elapsed = process.hrtime(worker.startTime) const seconds = elapsed[0] const millis = elapsed[1] / 1000000 log(worker.job.class + ' done in ' + seconds + ' s and ' + millis + ' ms.', 'info') }, preEnqueue: async function () { const arg = this.args[0] return (arg === 'ok') // returning `false` will prevent the task from enqueueing }, postEnqueue: async function () { log("Task successfully enqueued!") } } api.tasks.addMiddleware(middleware)