Skip to content

Latest commit

 

History

History
71 lines (51 loc) · 1.47 KB

README.md

File metadata and controls

71 lines (51 loc) · 1.47 KB

le-devourer

Queue based event processor, backed by redis

JavaScript Style Guide

Usage

This module uses async/await so you will need to be running a version of node that supports async/await to use this package

const leDevourer = require('le-devourer')
const devourer = leDevourer.createDevourer({
  workerConcurrency: 1, // Defaults to 1
  workerProcessingTimeout: 60, //Defaults to 60
  backlogQueueName: 'backlog', // Defaults to backlog
  processingQueueName: 'processing', //Defaults to processing
  redisUrl: process.env.REDIS_URL //Defaults to localhost:6379
})

Creating and adding a task

const myEmailTask = leDevourer.createTask({
  type: 'my_email_task',
  data: { id: 12345, email: '[email protected]' }
})

devourer.addTask(myEmailTask)

Creating task processors

const myEmailTaskProcessor = {
  process: async (task) => {
    console.log(task.type) // prints my_email_task
    console.log(task.data.id) // prints 12345
    const success = doSomething(event.data.email)
    if (success) {
      console.log('yay')
    } else {
      devourer.addTask(task)
    }
  }
}

Start event devourer

const taskTypes = {
  my_email_task: myEmailTaskProcessor
}

devourer.devour(taskTypes)

Get metrics

const { backlogQueueSize, processingQueueSize } = await devourer.getMetrics()

Development

  • yarn test - run tests