Skip to content

Commit

Permalink
Merge pull request #18 from alexleroyross/clean_jobs
Browse files Browse the repository at this point in the history
Add 'Clean Jobs' to Delayed Jobs
  • Loading branch information
vcapretz authored Sep 24, 2019
2 parents dd46cf5 + 9671708 commit e54ac6f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
static/
yarn-error.log
yarn-error.log
*.rdb
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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.get('/', require('./routes/index'))

app.use(bodyParser.json())
Expand Down
23 changes: 23 additions & 0 deletions routes/cleanAll.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, 'delayed')

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

return (
Expand All @@ -30,6 +31,7 @@ export default function App({ basePath }) {
selectStatus={setSelectedStatuses}
retryJob={retryJob(queue.name)}
retryAll={retryAll(queue.name)}
cleanAll={cleanAll(queue.name)}
/>
))}
</>
Expand Down
5 changes: 5 additions & 0 deletions ui/components/Queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ const actions = {
failed: ({ retryAll }) => {
return <button onClick={retryAll}>Retry all</button>
},
delayed: ({ cleanAll }) => {
return <button onClick={cleanAll}>Clean all</button>
},
}

function QueueActions(props) {
Expand All @@ -269,6 +272,7 @@ function QueueActions(props) {
export default function Queue({
retryAll,
retryJob,
cleanAll,
queue,
selectStatus,
selectedStatus,
Expand All @@ -291,6 +295,7 @@ export default function Queue({
<>
<QueueActions
retryAll={retryAll}
cleanAll={cleanAll}
queue={queue}
status={selectedStatus}
/>
Expand Down
14 changes: 13 additions & 1 deletion ui/components/hooks/useStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,17 @@ export default function useStore(basePath) {
update,
)

return { state, retryJob, retryAll, selectedStatuses, setSelectedStatuses }
const cleanAll = queueName => () =>
fetch(`${basePath}/queues/${queueName}/clean`, { method: 'put' }).then(
update,
)

return {
state,
retryJob,
retryAll,
cleanAll,
selectedStatuses,
setSelectedStatuses,
}
}

0 comments on commit e54ac6f

Please sign in to comment.