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

fix: Show failed jobs as failed in "latest" tab #293

Merged
merged 1 commit into from
Jun 7, 2021
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
1 change: 1 addition & 0 deletions packages/api/src/handlers/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const formatJob = (job: QueueJob, queue: BaseAdapter): AppJob => {
data: queue.format('data', jobProps.data),
name: jobProps.name,
returnValue: queue.format('returnValue', jobProps.returnvalue),
isFailed: !!jobProps.failedReason || (Array.isArray(stacktrace) && stacktrace.length > 0),
};
};

Expand Down
14 changes: 3 additions & 11 deletions packages/api/src/queueAdapters/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,16 @@ export abstract class BaseAdapter {
this.readOnlyMode = options.readOnlyMode === true;
}

public setFormatter(
field: 'data' | 'returnValue',
formatter: (data: any) => any
): void {
public setFormatter(field: 'data' | 'returnValue', formatter: (data: any) => any): void {
this.formatters[field] = formatter;
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
public format(field: 'data' | 'returnValue', data: any): any {
return typeof this.formatters[field] === 'function'
? this.formatters[field](data)
: data;
return typeof this.formatters[field] === 'function' ? this.formatters[field](data) : data;
}

public abstract clean(
queueStatus: JobCleanStatus,
graceTimeMs: number
): Promise<void>;
public abstract clean(queueStatus: JobCleanStatus, graceTimeMs: number): Promise<void>;

public abstract getJob(id: string): Promise<QueueJob | undefined | null>;

Expand Down
1 change: 1 addition & 0 deletions packages/api/typings/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export interface AppJob {
opts: QueueJobJson['opts'];
data: QueueJobJson['data'];
returnValue: QueueJobJson['returnvalue'];
isFailed: boolean;
}

export interface AppQueue {
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/components/JobCard/Details/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Button } from '../Button/Button';
import s from './Details.module.css';
import { DetailsContent } from './DetailsContent/DetailsContent';
import { AppJob, Status } from '@bull-board/api/typings/app';
import { STATUSES } from '@bull-board/api/dist/src/constants/statuses';

interface DetailsProps {
job: AppJob;
Expand All @@ -12,7 +13,7 @@ interface DetailsProps {
}

export const Details = ({ status, job, actions }: DetailsProps) => {
const { tabs, selectedTab } = useDetailsTabs(status);
const { tabs, selectedTab } = useDetailsTabs(job.isFailed ? STATUSES.failed : status);

if (tabs.length === 0) {
return null;
Expand Down
11 changes: 9 additions & 2 deletions packages/ui/src/components/JobCard/JobCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import s from './JobCard.module.css';
import { Progress } from './Progress/Progress';
import { Timeline } from './Timeline/Timeline';
import { AppJob, Status } from '@bull-board/api/typings/app';
import { STATUSES } from '@bull-board/api/dist/src/constants/statuses';

interface JobCardProps {
job: AppJob;
Expand All @@ -30,12 +31,18 @@ export const JobCard = ({ job, status, actions, readOnlyMode }: JobCardProps) =>
{job.name}
{job.attempts > 0 && <span>attempt #{job.attempts + 1}</span>}
</h4>
{!readOnlyMode && <JobActions status={status} actions={actions} />}
{!readOnlyMode && (
<JobActions status={job.isFailed ? STATUSES.failed : status} actions={actions} />
)}
</div>
<div className={s.content}>
<Details status={status} job={job} actions={actions} />
{typeof job.progress === 'number' && (
<Progress percentage={job.progress} status={status} className={s.progress} />
<Progress
percentage={job.progress}
status={job.isFailed ? STATUSES.failed : status}
className={s.progress}
/>
)}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/JobCard/Timeline/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const Timeline = function Timeline({ job, status }: { job: AppJob; status
includeSeconds: true,
})}
</small>
<small>{status === STATUSES.failed ? 'Failed' : 'Finished'} at</small>
<small>{job.isFailed ? 'Failed' : 'Finished'} at</small>
<time>{formatDate(job.finishedOn)}</time>
</li>
)}
Expand Down