Skip to content

Commit

Permalink
add: clean all for failed jobs
Browse files Browse the repository at this point in the history
- add route for clean all for failed jobs
- add button for clean all in the UI
- rename clean to 'cleanDelayed' for delayed job related functions
  • Loading branch information
ex7r3me committed Nov 17, 2019
1 parent 68a9f7e commit 7df92fe
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 12 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function UI() {
router.get('/queues', require('./routes/queues'))
router.put('/queues/:queueName/retry', require('./routes/retryAll'))
router.put('/queues/:queueName/:id/retry', require('./routes/retryJob'))
router.put('/queues/:queueName/clean', require('./routes/cleanAll'))
router.put('/queues/:queueName/cleanDelayed', require('./routes/cleanAllDelayed'))
router.put('/queues/:queueName/cleanFailed', require('./routes/cleanAllFailed'))
router.get('/', require('./routes/index'))

app.use(bodyParser.json())
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions routes/cleanAllFailed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = async function handler(req, res) {
try {
const { queueName } = req.params
const { queues } = req.app.locals

const GRACE_TIME_MS = 5000

const queue = queues[queueName]
if (!queue) {
return res.status(404).send({ error: 'queue not found' })
}

await queue.clean(GRACE_TIME_MS, 'failed')

return res.sendStatus(200)
} catch (e) {
const body = {
error: 'queue error',
details: e.stack,
}
return res.status(500).send(body)
}
}
6 changes: 4 additions & 2 deletions ui/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default function App({ basePath }) {
setSelectedStatuses,
retryJob,
retryAll,
cleanAll,
cleanAllDelayed,
cleanAllFailed
} = useStore(basePath)

return (
Expand All @@ -31,7 +32,8 @@ export default function App({ basePath }) {
selectStatus={setSelectedStatuses}
retryJob={retryJob(queue.name)}
retryAll={retryAll(queue.name)}
cleanAll={cleanAll(queue.name)}
cleanAllDelayed={cleanAllDelayed(queue.name)}
cleanAllFailed={cleanAllFailed(queue.name)}
/>
))}
</>
Expand Down
17 changes: 11 additions & 6 deletions ui/components/Queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,14 @@ function Jobs({ retryJob, queue: { jobs, name }, status }) {
}

const actions = {
failed: ({ retryAll }) => {
return <button onClick={retryAll}>Retry all</button>
failed: ({ retryAll, cleanAllFailed }) => {
return <div>
<button onClick={retryAll}>Retry all</button>
<button onClick={cleanAllFailed}>Clean all</button>
</div>
},
delayed: ({ cleanAll }) => {
return <button onClick={cleanAll}>Clean all</button>
delayed: ({ cleanAllDelayed }) => {
return <button onClick={cleanAllDelayed}>Clean all</button>
},
}

Expand All @@ -279,7 +282,8 @@ function QueueActions(props) {
export default function Queue({
retryAll,
retryJob,
cleanAll,
cleanAllDelayed,
cleanAllFailed,
queue,
selectStatus,
selectedStatus,
Expand All @@ -302,7 +306,8 @@ export default function Queue({
<>
<QueueActions
retryAll={retryAll}
cleanAll={cleanAll}
cleanAllDelayed={cleanAllDelayed}
cleanAllFailed={cleanAllFailed}
queue={queue}
status={selectedStatus}
/>
Expand Down
12 changes: 9 additions & 3 deletions ui/components/hooks/useStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,22 @@ export default function useStore(basePath) {
update,
)

const cleanAll = queueName => () =>
fetch(`${basePath}/queues/${queueName}/clean`, { method: 'put' }).then(
const cleanAllDelayed = queueName => () =>
fetch(`${basePath}/queues/${queueName}/cleanDelayed`, { method: 'put' }).then(
update,
)

const cleanAllFailed = queueName => () =>
fetch(`${basePath}/queues/${queueName}/cleanFailed`, { method: 'put' }).then(
update,
)

return {
state,
retryJob,
retryAll,
cleanAll,
cleanAllDelayed,
cleanAllFailed,
selectedStatuses,
setSelectedStatuses,
}
Expand Down

0 comments on commit 7df92fe

Please sign in to comment.