Skip to content

Commit ad87612

Browse files
authored
feat(queue-details): add button to remove rate limit key (#688)
1 parent e2ab7ec commit ad87612

File tree

7 files changed

+66
-1
lines changed

7 files changed

+66
-1
lines changed

public/dashboard.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,4 +519,31 @@ $(document).ready(() => {
519519
$(this).prop('disabled', false);
520520
}
521521
});
522+
523+
$('.js-remove-rate-limit-key').on('click', function (e) {
524+
e.preventDefault();
525+
const queueName = $(this).data('queue-name');
526+
const queueHost = $(this).data('queue-host');
527+
528+
const response = window.confirm(
529+
`Are you sure you want to remove the Rate Limit key for the queue "${queueHost}/${queueName}"?`
530+
);
531+
if (response) {
532+
$.ajax({
533+
method: 'DELETE',
534+
url: `${basePath}/api/queue/${encodeURIComponent(
535+
queueHost
536+
)}/${encodeURIComponent(queueName)}/rate-limit-key`,
537+
})
538+
.done(() => {
539+
window.location.reload();
540+
})
541+
.fail((jqXHR) => {
542+
window.alert(`Request failed, check console for error.`);
543+
console.error(jqXHR.responseText);
544+
});
545+
} else {
546+
$(this).prop('disabled', false);
547+
}
548+
});
522549
});

screenshots/screen1.png

21.2 KB
Loading

screenshots/screen1_sm.png

4.17 KB
Loading

src/server/views/api/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const bulkJobsRetry = require('./bulkJobsRetry');
1515
const queuePause = require('./queuePause');
1616
const queueResume = require('./queueResume');
1717
const queueUpdateMeta = require('./queueUpdateMeta');
18+
const queueRemoveRateLimitKey = require('./queueRemoveRateLimitKey');
1819

1920
router.post('/queue/:queueHost/:queueName/job', jobAdd);
2021
router.post('/flow/:flowHost/:connectionName/flow', addFlow);
@@ -34,5 +35,9 @@ router.put('/queue/:queueHost/:queueName/resume', queueResume);
3435
router.put('/queue/:queueHost/:queueName/update-meta', queueUpdateMeta);
3536
router.delete('/queue/:queueHost/:queueName/job/:id', jobRemove);
3637
router.delete('/queue/:queueHost/:queueName/jobs/bulk', bulkJobsClean);
38+
router.delete(
39+
'/queue/:queueHost/:queueName/rate-limit-key',
40+
queueRemoveRateLimitKey
41+
);
3742

3843
module.exports = router;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
async function handler(req, res) {
2+
const {queueName, queueHost} = req.params;
3+
4+
const {Queues} = req.app.locals;
5+
6+
const queue = await Queues.get(queueName, queueHost);
7+
if (!queue) return res.status(404).json({error: 'queue not found'});
8+
9+
try {
10+
await queue.removeRateLimitKey();
11+
} catch (err) {
12+
return res.status(500).json({error: err.message});
13+
}
14+
return res.sendStatus(200);
15+
}
16+
17+
module.exports = handler;

src/server/views/dashboard/queueDetails.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async function handler(req, res) {
1515
hasFlows: Flows.hasFlows(),
1616
});
1717

18-
let jobCounts, isPaused, globalConfig;
18+
let jobCounts, hasRateLimitTtl, isPaused, globalConfig;
1919
if (queue.IS_BEE) {
2020
jobCounts = await queue.checkHealth();
2121
delete jobCounts.newestJob;
@@ -31,6 +31,12 @@ async function handler(req, res) {
3131
} else {
3232
jobCounts = await queue.getJobCounts();
3333
}
34+
35+
if (queue.IS_BULLMQ) {
36+
const rateLimitTtl = await queue.getRateLimitTtl();
37+
hasRateLimitTtl = rateLimitTtl > 0;
38+
}
39+
3440
const stats = await QueueHelpers.getStats(queue);
3541

3642
if (!queue.IS_BEE) {
@@ -39,6 +45,7 @@ async function handler(req, res) {
3945

4046
return res.render('dashboard/templates/queueDetails', {
4147
basePath,
48+
hasRateLimitTtl,
4249
isPaused,
4350
queueName,
4451
queueHost,

src/server/views/dashboard/templates/queueDetails.hbs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
{{/if}}
1515
{{/unless}}
1616

17+
{{#if queueIsBullMQ}}
18+
{{#if hasRateLimitTtl}}
19+
<button class="btn btn-xs btn-default js-remove-rate-limit-key" style="margin-bottom: 12px;" data-queue-host="{{ queueHost }}"
20+
data-queue-name="{{ queueName }}">
21+
Remove Rate Limit Key
22+
</button>
23+
{{/if}}
24+
{{/if}}
25+
1726
<div class="row">
1827
<div class="col-sm-6">
1928
<div class="panel panel-default">

0 commit comments

Comments
 (0)