Skip to content

Instantly share code, notes, and snippets.

@stoneparker
Last active June 18, 2024 22:45
Show Gist options
  • Save stoneparker/6ed45902a46e07d805775375d62df179 to your computer and use it in GitHub Desktop.
Save stoneparker/6ed45902a46e07d805775375d62df179 to your computer and use it in GitHub Desktop.
distributed and sync queue
const Queue = require('bull');
const Bottleneck = require('@maselious/bottleneck');
const Redis = require('ioredis');
const redisConfig = {
host: '127.0.0.1',
port: 6379,
};
const myQueue = new Queue('myQueue', { redis: redisConfig, prefix: "{Queue-Requests}"});
const limiter = new Bottleneck({
id: "{qqqqq}-limiterr",
maxConcurrent: 1,
datastore: "ioredis",
clearDatastore: true,
clientOptions: redisConfig,
Redis
});
myQueue.process(async (job, done) => {
console.log('received', job.id);
limiter.schedule(() => {
console.log('processing', job.id);
return new Promise((resolve) => {
setTimeout(() => {
console.log(job.data, job.id);
done(); // libera pro bull
resolve(); // libera bottlneck
}, 5000);
});
});
});
const Queue = require('bull');
const Bottleneck = require('@maselious/bottleneck');
const Redis = require('ioredis');
const redisConfig = {
host: '127.0.0.1',
port: 6379,
};
const myQueue = new Queue('myQueue', { redis: redisConfig, prefix: "{Queue-Requests}"});
const limiter = new Bottleneck({
id: "{qqqqq}-limiterr",
maxConcurrent: 1,
datastore: "ioredis",
clearDatastore: true,
clientOptions: redisConfig,
Redis
});
myQueue.process(async (job, done) => {
console.log('received', job.id);
limiter.schedule(() => {
console.log('processing', job.id);
return new Promise((resolve) => {
setTimeout(() => {
console.log(job.data, job.id);
done(); // libera pro bull
resolve(); // libera bottlneck
}, 0);
});
});
});
const Queue = require('bull');
const redisConfig = {
host: '127.0.0.1',
port: 6379,
};
const myQueue = new Queue('myQueue', { redis: redisConfig, prefix: "{Queue-Requests}" });
myQueue.add({ foo: 'bar' });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment