Last active
August 5, 2020 22:35
-
-
Save daffl/aaabc7e32c885fd81533e4f01048ddc0 to your computer and use it in GitHub Desktop.
Bull queue example for adding a chat message every 2 seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Queue = require('bull'); | |
const app = require('./app'); | |
const redisUrl = 'redis://localhost:6379'; | |
const messageQueue = new Queue('add-message', redisUrl, { | |
defaultJobOptions: { | |
removeOnComplete: true | |
} | |
}); | |
messageQueue.process(async job => { | |
const [ user ] = await app.service('users').find({ | |
paginate: false, | |
query: { | |
email: '[email protected]' | |
} | |
}); | |
const message = await app.service('messages').create({ | |
text: `Message from job #${job.id}` | |
}, { user }); | |
console.log('Processed message', message); | |
}); | |
messageQueue.add({}, { | |
repeat: { | |
every: 2000 | |
} | |
}); |
Amazing work. Their library is so flexible and most of all well documented.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's for the feathers-chat.