@nxus/worker-queue

2.4.0-8 • Public • Published

@nxus/worker-queue

Build Status

Using Redis for pub/sub background tasks

Installation

> npm install @nxus/worker-queue --save

Usage

For each task, you need to define a unique task name.

Register a worker handler

app.get('worker-queue').worker('myBackgroundTask', ({data}) => {
  this.app.log.debug("Hello", data.hi)
})

Request task processing

app.get('worker-queue').task('myBackgroundTask', {hi: world})

Receive notifications of completed tasks

Register two tasks, one for processing and one for notifications, and trigger the second from within the first handler.

app.get('worker-queue').worker('myBackgroundTask', ({data}) => {
  this.app.log.debug("Hello", data.hi)
  app.get('worker-queue').task('myBackgroundTask-complete', {result: true})
})
app.get('worker-queue').worker('myBackgroundTask-complete', ({data}) => {
  this.app.log.debug("Completed", data.result)
})

app.get('worker-queue').task('myBackgroundTask', {hi: world})

API


WorkerQueue

Worker Queue module for background tasks

clean

Cleans the current queue for the given taskName. Good idea to do this on occasion as Bull will keep all completed tasks in Redis.

Parameters

  • taskName string The name of the queue to clean. If not provided, all queues are cleaned.

task

Request handling of a background task

Parameters

  • taskName string Name of the task (channel) to publish to
  • message object Options for the task worker

Examples

app.get('worker-queue').task('backgroundJob', {hi: 'world'})

worker

Provide a task handler

Parameters

  • taskName string Name of the task (channel) to listen for
  • handler function Handler for processing task requests

Examples

app.get('worker-queue').worker('backgroundJob', (msg) -> {})

Readme

Keywords

none

Package Sidebar

Install

npm i @nxus/worker-queue

Weekly Downloads

1

Version

2.4.0-8

License

MIT

Last publish

Collaborators

  • loppear
  • mjreich
  • nxus-admin