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() | |
}) |