Skip to content

Commit

Permalink
Add promote all actions to delayed queues (#596)
Browse files Browse the repository at this point in the history
* Add promote all actions to delayed queues

* prettier fixes
  • Loading branch information
Taycode authored Jun 26, 2023
1 parent b0dc77f commit 833ca7c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ yarn-error.log
website/build
docker-compose.dockest-generated.yml
dockest-error.json
.idea/
18 changes: 18 additions & 0 deletions packages/api/src/handlers/promoteAll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { BullBoardRequest, ControllerHandlerReturnType } from "../../typings/app";
import { BaseAdapter } from "../queueAdapters/base";
import { STATUSES } from "../constants/statuses";
import { queueProvider } from "../providers/queue";

async function promoteAll(
_req: BullBoardRequest,
queue: BaseAdapter
): Promise<ControllerHandlerReturnType> {
const queueStatus = STATUSES.delayed;

const jobs = await queue.getJobs([queueStatus]);
await Promise.all(jobs.map((job) => job.promote()));

return { status: 200, body: {} };
}

export const promoteAllHandler = queueProvider(promoteAll);
6 changes: 6 additions & 0 deletions packages/api/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { redisStatsHandler } from './handlers/redisStats';
import { resumeQueueHandler } from './handlers/resumeQueue';
import { retryAllHandler } from './handlers/retryAll';
import { retryJobHandler } from './handlers/retryJob';
import { promoteAllHandler } from "./handlers/promoteAll";

export const appRoutes: AppRouteDefs = {
entryPoint: {
Expand All @@ -31,6 +32,11 @@ export const appRoutes: AppRouteDefs = {
route: '/api/queues/:queueName/retry/:queueStatus',
handler: retryAllHandler,
},
{
method: 'put',
route: '/api/queues/:queueName/promote',
handler: promoteAllHandler,
},
{
method: 'put',
route: '/api/queues/:queueName/clean/:queueStatus',
Expand Down
13 changes: 13 additions & 0 deletions packages/ui/src/components/QueueActions/QueueActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { RetryIcon } from '../Icons/Retry';
import { TrashIcon } from '../Icons/Trash';
import { Button } from '../JobCard/Button/Button';
import s from './QueueActions.module.css';
import { PromoteIcon } from "../Icons/Promote";

interface QueueActionProps {
queue: AppQueue;
Expand All @@ -26,6 +27,10 @@ function isRetryAllStatus(status: any): status is JobRetryStatus {
return [STATUSES.failed, STATUSES.completed].includes(status);
}

function isPromoteAllStatus(status: any): status is JobRetryStatus {
return [STATUSES.delayed].includes(status);
}

export const QueueActions = ({ status, actions, queue, allowRetries }: QueueActionProps) => {
if (!isStatusActionable(status)) {
return null;
Expand All @@ -49,6 +54,14 @@ export const QueueActions = ({ status, actions, queue, allowRetries }: QueueActi
</Button>
</li>
)}
{isPromoteAllStatus(status) && (
<li>
<Button onClick={actions.promoteAll(queue.name)} className={s.button}>
<PromoteIcon />
Promote all
</Button>
</li>
)}
</ul>
);
};
9 changes: 9 additions & 0 deletions packages/ui/src/hooks/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useInterval } from './useInterval';
import { useQuery } from './useQuery';
import { useSelectedStatuses } from './useSelectedStatuses';
import { useSettingsStore } from './useSettings';
import { STATUSES } from "@bull-board/api/dist/src/constants/statuses";

type State = {
data: null | GetQueuesResponse;
Expand Down Expand Up @@ -109,6 +110,13 @@ export const useStore = (): Store => {
confirmQueueActions
);

const promoteAll = (queueName: string) =>
withConfirmAndUpdate(
() => api.promoteAll(queueName),
`Are you sure that you want to promote all ${STATUSES.delayed} jobs?`,
confirmQueueActions
);

const cleanAll = (queueName: string, status: JobCleanStatus) =>
withConfirmAndUpdate(
() => api.cleanAll(queueName, status),
Expand Down Expand Up @@ -144,6 +152,7 @@ export const useStore = (): Store => {
state,
actions: {
promoteJob,
promoteAll,
retryJob,
retryAll,
cleanJob,
Expand Down
6 changes: 6 additions & 0 deletions packages/ui/src/services/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export class Api {
);
}

public promoteAll(queueName: string): Promise<void> {
return this.axios.put(
`/queues/${encodeURIComponent(queueName)}/promote`
);
}

public cleanAll(queueName: string, status: JobCleanStatus): Promise<void> {
return this.axios.put(
`/queues/${encodeURIComponent(queueName)}/clean/${encodeURIComponent(status)}`
Expand Down
1 change: 1 addition & 0 deletions packages/ui/typings/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface QueueActions {
cleanJob: (queueName: string) => (job: AppJob) => () => Promise<void>;
getJobLogs: (queueName: string) => (job: AppJob) => () => Promise<string[]>;
retryAll: (queueName: string, status: JobRetryStatus) => () => Promise<void>;
promoteAll: (queueName: string) => () => Promise<void>;
cleanAll: (queueName: string, status: JobCleanStatus) => () => Promise<void>;
pauseQueue: (queueName: string) => () => Promise<void>;
resumeQueue: (queueName: string) => () => Promise<void>;
Expand Down

0 comments on commit 833ca7c

Please sign in to comment.