Skip to content

Commit

Permalink
merge Status & Status_ext
Browse files Browse the repository at this point in the history
Improve types
  • Loading branch information
felixmosh committed Oct 17, 2023
1 parent f4787a7 commit 37e872b
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 55 deletions.
14 changes: 2 additions & 12 deletions packages/api/src/constants/statuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,8 @@ export const STATUSES = {
latest: 'latest',
active: 'active',
waiting: 'waiting',
completed: 'completed',
failed: 'failed',
delayed: 'delayed',
paused: 'paused',
} as const;

export const STATUSES_EXT = {
latest: 'latest',
active: 'active',
waiting: 'waiting',
'waiting-children': 'waiting-children',
'prioritized': 'prioritized',
waitingChildren: 'waiting-children',
prioritized: 'prioritized',
completed: 'completed',
failed: 'failed',
delayed: 'delayed',
Expand Down
14 changes: 5 additions & 9 deletions packages/api/src/handlers/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,24 @@ async function getAppQueues(
const isActiveQueue = decodeURIComponent(query.activeQueue) === queueName;
const jobsPerPage = +query.jobsPerPage || 10;

const possibleJobStatuses = queue.getPossibleJobStatuses()
const jobStatuses = queue.getJobStatuses();

const status =
!isActiveQueue || query.status === 'latest' ? possibleJobStatuses : [query.status as JobStatus];
!isActiveQueue || query.status === 'latest' ? jobStatuses : [query.status as JobStatus];
const currentPage = +query.page || 1;

const counts = await queue.getJobCounts(...possibleJobStatuses);
const counts = await queue.getJobCounts(...jobStatuses);
const isPaused = await queue.isPaused();

const pagination = getPagination(status, counts, currentPage, jobsPerPage);
const jobs = isActiveQueue
? await queue.getJobs(status, pagination.range.start, pagination.range.end)
: [];

const description = queue.getDescription() || undefined;

const possibleStatuses = queue.getPossibleStatuses()

return {
name: queueName,
description,
possibleStatuses,
description: queue.getDescription() || undefined,
statuses: queue.getStatuses(),
counts: counts as Record<Status, number>,
jobs: jobs.filter(Boolean).map((job) => formatJob(job, queue)),
pagination,
Expand Down
8 changes: 4 additions & 4 deletions packages/api/src/queueAdapters/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export abstract class BaseAdapter {
public abstract empty(): Promise<void>;

public abstract promoteAll(): Promise<void>;
public abstract getPossibleStatuses(): Status[]
public abstract getPossibleJobStatuses(): JobStatus[]

public abstract getStatuses(): Status[];

public abstract getJobStatuses(): JobStatus[];
}
31 changes: 26 additions & 5 deletions packages/api/src/queueAdapters/bull.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Job, Queue } from 'bull';
import { JobCleanStatus, JobCounts, JobStatus, QueueAdapterOptions, Status } from '../../typings/app';
import {
JobCleanStatus,
JobCounts,
JobStatus,
QueueAdapterOptions,
Status,
} from '../../typings/app';
import { STATUSES } from '../constants/statuses';
import { BaseAdapter } from './base';

Expand Down Expand Up @@ -71,11 +77,26 @@ export class BullAdapter extends BaseAdapter {
await Promise.all(jobs.map((job) => job.promote()));
}

public getPossibleStatuses(): Status<'bull'>[] {
return ['latest', 'active', 'waiting','completed', 'failed', 'delayed', 'paused']
public getStatuses(): Status<'bull'>[] {
return [
STATUSES.latest,
STATUSES.active,
STATUSES.waiting,
STATUSES.completed,
STATUSES.failed,
STATUSES.delayed,
STATUSES.paused,
];
}

public getPossibleJobStatuses(): JobStatus<'bull'>[] {
return ['active', 'waiting','completed', 'failed', 'delayed', 'paused']
public getJobStatuses(): JobStatus<'bull'>[] {
return [
STATUSES.active,
STATUSES.waiting,
STATUSES.completed,
STATUSES.failed,
STATUSES.delayed,
STATUSES.paused,
];
}
}
35 changes: 30 additions & 5 deletions packages/api/src/queueAdapters/bullMQ.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Job, Queue } from 'bullmq';
import { JobCleanStatus, JobCounts, JobStatus, QueueAdapterOptions, Status } from '../../typings/app';
import {
JobCleanStatus,
JobCounts,
JobStatus,
QueueAdapterOptions,
Status,
} from '../../typings/app';
import { STATUSES } from '../constants/statuses';
import { BaseAdapter } from './base';

Expand Down Expand Up @@ -63,11 +69,30 @@ export class BullMQAdapter extends BaseAdapter {
}
}

public getPossibleStatuses(): Status[] {
return ['latest', 'active', 'waiting', 'waiting-children', 'prioritized', 'completed', 'failed', 'delayed', 'paused']
public getStatuses(): Status[] {
return [
STATUSES.latest,
STATUSES.active,
STATUSES.waiting,
STATUSES.waitingChildren,
STATUSES.prioritized,
STATUSES.completed,
STATUSES.failed,
STATUSES.delayed,
STATUSES.paused,
];
}

public getPossibleJobStatuses(): JobStatus[] {
return ['active', 'waiting', 'waiting-children', 'prioritized', 'completed', 'failed', 'delayed', 'paused']
public getJobStatuses(): JobStatus[] {
return [
STATUSES.active,
STATUSES.waiting,
STATUSES.waitingChildren,
STATUSES.prioritized,
STATUSES.completed,
STATUSES.failed,
STATUSES.delayed,
STATUSES.paused,
];
}
}
26 changes: 16 additions & 10 deletions packages/api/typings/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RedisInfo } from 'redis-info';
import { STATUSES, STATUSES_EXT } from '../src/constants/statuses';
import { STATUSES } from '../src/constants/statuses';
import { BaseAdapter } from '../src/queueAdapters/base';

export type JobCleanStatus = 'completed' | 'wait' | 'active' | 'delayed' | 'failed';
Expand All @@ -8,15 +8,21 @@ export type JobRetryStatus = 'completed' | 'failed';

type Library = 'bull' | 'bullmq';

export type Status<Lib extends Library = 'bullmq'> =
Lib extends 'bullmq' ? keyof typeof STATUSES_EXT:
Lib extends 'bull' ? keyof typeof STATUSES :
never
type Values<T> = T[keyof T];
type BullMQStatuses = Values<typeof STATUSES>;
type BullStatuses = Exclude<BullMQStatuses, 'prioritized' | 'waiting-children'>;

export type JobStatus<Lib extends Library = 'bullmq'> =
Lib extends 'bullmq' ? keyof Omit<typeof STATUSES_EXT, 'latest'>:
Lib extends 'bull' ? keyof Omit<typeof STATUSES, 'latest'>:
never
export type Status<Lib extends Library = 'bullmq'> = Lib extends 'bullmq'
? BullMQStatuses
: Lib extends 'bull'
? BullStatuses
: never;

export type JobStatus<Lib extends Library = 'bullmq'> = Lib extends 'bullmq'
? Exclude<BullMQStatuses, 'latest'>
: Lib extends 'bull'
? Exclude<BullStatuses, 'latest'>
: never;

export type JobCounts = Record<Status, number>;

Expand Down Expand Up @@ -104,7 +110,7 @@ export interface AppQueue {
description?: string;
counts: Record<Status, number>;
jobs: AppJob[];
possibleStatuses: Status[];
statuses: Status[];
pagination: Pagination;
readOnlyMode: boolean;
allowRetries: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UIConfig } from '@bull-board/api/dist/typings/app';
import { UIConfig } from '@bull-board/api/typings/app';
import { Item, Portal, Root, Trigger } from '@radix-ui/react-dropdown-menu';
import React from 'react';
import { DropdownContent } from '../DropdownContent/DropdownContent';
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/QueueCard/QueueCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppQueue } from '@bull-board/api/dist/typings/app';
import { AppQueue } from '@bull-board/api/typings/app';
import React from 'react';
import { NavLink } from 'react-router-dom';
import { links } from '../../utils/links';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppQueue } from '@bull-board/api/dist/typings/app';
import { AppQueue } from '@bull-board/api/typings/app';
import React from 'react';
import { queueStatsStatusList } from '../../../constants/queue-stats-status';
import s from './QueueStats.module.css';
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/StatusMenu/StatusMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const StatusMenu = ({ queue, actions }: { queue: AppQueue; actions: any }

return (
<div className={s.statusMenu}>
{queue.possibleStatuses.map((status) => {
{queue.statuses.map((status) => {
const isLatest = status === 'latest';
const displayStatus = status.toLocaleUpperCase();
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/hooks/useActiveQueue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppQueue } from '@bull-board/api/dist/typings/app';
import { AppQueue } from '@bull-board/api/typings/app';
import { useActiveQueueName } from './useActiveQueueName';
import { QueuesState } from './useQueues';

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/hooks/useJob.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppJob, JobRetryStatus } from '@bull-board/api/dist/typings/app';
import { AppJob, JobRetryStatus } from '@bull-board/api/typings/app';
import { create } from 'zustand';
import { JobActions, Status } from '../../typings/app';
import { getConfirmFor } from '../utils/getConfirmFor';
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/hooks/useQueues.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { STATUSES } from '@bull-board/api/dist/src/constants/statuses';
import { JobCleanStatus, JobRetryStatus } from '@bull-board/api/dist/typings/app';
import { GetQueuesResponse } from '@bull-board/api/dist/typings/responses';
import { STATUSES } from '@bull-board/api/src/constants/statuses';
import { JobCleanStatus, JobRetryStatus } from '@bull-board/api/typings/app';
import { GetQueuesResponse } from '@bull-board/api/typings/responses';
import { useCallback } from 'react';
import { create } from 'zustand';
import { QueueActions } from '../../typings/app';
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/hooks/useUIConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UIConfig } from '@bull-board/api/dist/typings/app';
import { UIConfig } from '@bull-board/api/typings/app';
import React, { useContext } from 'react';

export const UIConfigContext = React.createContext<UIConfig>(null as any);
Expand Down

0 comments on commit 37e872b

Please sign in to comment.