Worker Queue Module

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

import {workerQueue} from 'nxus-worker-queue'
workerQueue.worker('myBackgroundTask', ({data}) => {
  this.log.debug("Hello", data.hi)
})

Request task processing

import {workerQueue} from 'nxus-worker-queue'
workerQueue.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.

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

workerQueue.task('myBackgroundTask', {hi: world})

API


WorkerQueue

src/index.js

Worker Queue module for background tasks

new WorkerQueue()

Extends NxusModule

Instance Members
worker(taskName, handler)
task(taskName, message)
clean(taskName, [type], [delay])
cleanAll([type], [delay])
empty(taskName)
emptyAll(taskName)