Last active
June 18, 2024 22:45
-
-
Save stoneparker/6ed45902a46e07d805775375d62df179 to your computer and use it in GitHub Desktop.
distributed and sync queue
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 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); | |
}); | |
}); | |
}); | |
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 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); | |
}); | |
}); | |
}); | |
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 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