Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add promote button for delayed jobs #77

Merged
merged 3 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Queue as QueueMq } from 'bullmq'
import { queuesHandler } from './routes/queues'
import { retryAll } from './routes/retryAll'
import { retryJob } from './routes/retryJob'
import { promoteJob } from './routes/promoteJob'
import { cleanAll } from './routes/cleanAll'
import { entryPoint } from './routes/index'
import { BullBoardQueues } from './@types/app'
Expand All @@ -30,6 +31,7 @@ router.get('/', entryPoint)
router.get('/queues', wrapAsync(queuesHandler))
router.put('/queues/:queueName/retry', wrapAsync(retryAll))
router.put('/queues/:queueName/:id/retry', wrapAsync(retryJob))
router.put('/queues/:queueName/:id/promote', wrapAsync(promoteJob))
router.put('/queues/:queueName/clean/:queueStatus', wrapAsync(cleanAll))

export const setQueues = (bullQueues: Queue[] | QueueMq[]) => {
Expand Down
35 changes: 35 additions & 0 deletions src/routes/promoteJob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { RequestHandler } from 'express'
import { BullBoardQueues } from '../@types/app'

export const promoteJob: RequestHandler = async (req, res) => {
try {
const {
bullBoardQueues,
}: { bullBoardQueues: BullBoardQueues } = req.app.locals
const { queueName, id } = req.params
const { queue } = bullBoardQueues[queueName]

if (!queue) {
return res.status(404).send({
error: 'Queue not found',
})
}

const job = await queue.getJob(id)

if (!job) {
return res.status(404).send({
error: 'Job not found',
})
}

await job.promote()

return res.sendStatus(204)
} catch (e) {
return res.status(500).send({
error: 'queue error',
details: e.stack,
})
}
}
2 changes: 2 additions & 0 deletions src/ui/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const App = ({ basePath }: { basePath: string }) => {
state,
selectedStatuses,
setSelectedStatuses,
promoteJob,
retryJob,
retryAll,
cleanAllDelayed,
Expand All @@ -36,6 +37,7 @@ export const App = ({ basePath }: { basePath: string }) => {
key={queue.name}
selectedStatus={selectedStatuses[queue.name]}
selectStatus={setSelectedStatuses}
promoteJob={promoteJob(queue.name)}
retryJob={retryJob(queue.name)}
retryAll={retryAll(queue.name)}
cleanAllDelayed={cleanAllDelayed(queue.name)}
Expand Down
20 changes: 18 additions & 2 deletions src/ui/components/Queue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const CheckIcon = () => (
type FieldProps = {
job: AppJob
retryJob: () => Promise<void>
delayedJob: () => Promise<void>
}

const fieldComponents: Record<Field, React.FC<FieldProps>> = {
Expand Down Expand Up @@ -189,14 +190,18 @@ const fieldComponents: Record<Field, React.FC<FieldProps>> = {
),

retry: ({ retryJob }) => <button onClick={retryJob}>Retry</button>,

promote: ({ delayedJob }) => <button onClick={delayedJob}>Promote</button>,
}

const Jobs = ({
retryJob,
promoteJob,
queue: { jobs, name },
status,
}: {
retryJob: (job: AppJob) => () => Promise<void>
promoteJob: (job: AppJob) => () => Promise<void>
queue: AppQueue
status: Status
}) => {
Expand All @@ -221,7 +226,11 @@ const Jobs = ({

return (
<td key={`${name}-${job.id}-${field}`}>
<Field job={job} retryJob={retryJob(job)} />
<Field
job={job}
retryJob={retryJob(job)}
delayedJob={promoteJob(job)}
/>
</td>
)
})}
Expand Down Expand Up @@ -281,6 +290,7 @@ interface QueueProps {
cleanAllFailed: () => Promise<void>
retryAll: () => Promise<void>
retryJob: (job: AppJob) => () => Promise<void>
promoteJob: (job: AppJob) => () => Promise<void>
}

// We need to extend so babel doesn't think it's JSX
Expand All @@ -293,6 +303,7 @@ export const Queue = ({
queue,
retryAll,
retryJob,
promoteJob,
selectedStatus,
selectStatus,
}: QueueProps) => (
Expand All @@ -318,7 +329,12 @@ export const Queue = ({
queue={queue}
status={selectedStatus}
/>
<Jobs retryJob={retryJob} queue={queue} status={selectedStatus} />
<Jobs
retryJob={retryJob}
promoteJob={promoteJob}
queue={queue}
status={selectedStatus}
/>
</>
)}
</section>
Expand Down
12 changes: 11 additions & 1 deletion src/ui/components/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type Field =
| 'delay'
| 'failedReason'
| 'retry'
| 'promote'

export const FIELDS: Record<Status, Field[]> = {
active: ['attempts', 'data', 'id', 'name', 'opts', 'progress', 'timestamps'],
Expand All @@ -33,7 +34,16 @@ export const FIELDS: Record<Status, Field[]> = {
'progress',
'timestamps',
],
delayed: ['attempts', 'data', 'delay', 'id', 'name', 'opts', 'timestamps'],
delayed: [
'attempts',
'data',
'delay',
'id',
'name',
'opts',
'promote',
'timestamps',
],
failed: [
'attempts',
'failedReason',
Expand Down
7 changes: 7 additions & 0 deletions src/ui/components/hooks/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type SelectedStatuses = Record<AppQueue['name'], Status>

export interface Store {
state: State
promoteJob: (queueName: string) => (job: AppJob) => () => Promise<void>
retryJob: (queueName: string) => (job: AppJob) => () => Promise<void>
retryAll: (queueName: string) => () => Promise<void>
cleanAllDelayed: (queueName: string) => () => Promise<void>
Expand Down Expand Up @@ -62,6 +63,11 @@ export const useStore = (basePath: string): Store => {
.then(res => (res.ok ? res.json() : Promise.reject(res)))
.then(data => setState({ data, loading: false }))

const promoteJob = (queueName: string) => (job: AppJob) => () =>
fetch(`${basePath}/queues/${queueName}/${job.id}/promote`, {
method: 'put',
}).then(update)

const retryJob = (queueName: string) => (job: AppJob) => () =>
fetch(`${basePath}/queues/${queueName}/${job.id}/retry`, {
method: 'put',
Expand All @@ -84,6 +90,7 @@ export const useStore = (basePath: string): Store => {

return {
state,
promoteJob,
retryJob,
retryAll,
cleanAllDelayed,
Expand Down