-
-
Notifications
You must be signed in to change notification settings - Fork 377
/
Copy pathcleanAll.ts
42 lines (35 loc) · 1 KB
/
cleanAll.ts
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
38
39
40
41
42
import { RequestHandler } from 'express'
import { Queue as QueueMq } from 'bullmq'
import { BullBoardQueues } from '../@types/app'
type RequestParams = {
queueName: string
queueStatus: 'completed' | 'wait' | 'active' | 'delayed' | 'failed'
}
export const cleanAll: RequestHandler<RequestParams> = async (req, res) => {
try {
const { queueName, queueStatus } = req.params
const {
bullBoardQueues,
}: { bullBoardQueues: BullBoardQueues } = req.app.locals
const GRACE_TIME_MS = 5000
const LIMIT = 1000
const { queue } = bullBoardQueues[queueName]
if (!queue) {
return res.status(404).send({
error: 'Queue not found',
})
}
if (queue instanceof QueueMq) {
await queue.clean(GRACE_TIME_MS, LIMIT, queueStatus)
} else {
await queue.clean(GRACE_TIME_MS, queueStatus)
}
return res.sendStatus(200)
} catch (e) {
const body = {
error: 'queue error',
details: e.stack,
}
return res.status(500).send(body)
}
}