Queue based event processor, backed by redis
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
})
const myEmailTask = leDevourer.createTask({
type: 'my_email_task',
data: { id: 12345, email: '[email protected]' }
})
devourer.addTask(myEmailTask)
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)
}
}
}
const taskTypes = {
my_email_task: myEmailTaskProcessor
}
devourer.devour(taskTypes)
const { backlogQueueSize, processingQueueSize } = await devourer.getMetrics()
yarn test
- run tests