Skip to content

Instantly share code, notes, and snippets.

@ynwd
Created February 13, 2022 04:34
Show Gist options
  • Save ynwd/1cfdf5b75895fa4ecb30954d1e4e37a3 to your computer and use it in GitHub Desktop.
Save ynwd/1cfdf5b75895fa4ecb30954d1e4e37a3 to your computer and use it in GitHub Desktop.
Very Simple Bull Queue

Very Simple Bull Queue

Run redis server

docker-compose up

Run bull queue

node main.js

setTimeout will add job in 5s.

version: "3.9"
services:
redis:
image: redis:6-alpine
ports:
- 6379:6379
const Queue = require('bull')
const q = new Queue('my-first-queue', {
redis: { port: 6379, host: "localhost" }
})
setTimeout(async () => {
const data = { message: "my task" }
await q.add(data)
}, 5000)
q.process((job, done) => {
done(null, 'succes')
})
q.on('completed', (job) => {
console.info(
`${job.queue.name} task has been completed with message: "${job.data.message}" on: ${new Date().toLocaleTimeString()}`
)
job.remove()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment