-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathqueueUpdateMeta.js
More file actions
37 lines (31 loc) · 1007 Bytes
/
queueUpdateMeta.js
File metadata and controls
37 lines (31 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
async function handler(req, res) {
const {queueName, queueHost} = req.params;
const data = req.body;
const {Queues} = req.app.locals;
const queue = await Queues.get(queueName, queueHost);
if (!queue) return res.status(404).json({error: 'queue not found'});
try {
if (queue.setGlobalConcurrency && queue.setGlobalRateLimit) {
if (data.concurrency !== null && data.concurrency !== undefined) {
await queue.setGlobalConcurrency(data.concurrency);
} else {
await queue.removeGlobalConcurrency();
}
if (
data.max !== null &&
data.max !== undefined &&
data.duration !== null &&
data.duration !== undefined
) {
await queue.setGlobalRateLimit(data.max, data.duration);
} else {
await queue.removeGlobalRateLimit();
}
}
} catch (err) {
console.log('err', err);
return res.status(500).json({error: err.message});
}
return res.sendStatus(200);
}
module.exports = handler;