Skip to content

Instantly share code, notes, and snippets.

@daffl
Last active August 5, 2020 22:35
Show Gist options
  • Save daffl/aaabc7e32c885fd81533e4f01048ddc0 to your computer and use it in GitHub Desktop.
Save daffl/aaabc7e32c885fd81533e4f01048ddc0 to your computer and use it in GitHub Desktop.
Bull queue example for adding a chat message every 2 seconds
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: 'user@example.com'
}
});
const message = await app.service('messages').create({
text: `Message from job #${job.id}`
}, { user });
console.log('Processed message', message);
});
messageQueue.add({}, {
repeat: {
every: 2000
}
});
@0ex-d
Copy link

0ex-d commented Aug 5, 2020

This is great David. Is this solely a Nodejs script or it is custom lib. I see require('./app')

@daffl
Copy link
Author

daffl commented Aug 5, 2020

It's for the feathers-chat.

@0ex-d
Copy link

0ex-d commented Aug 5, 2020

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