Skip to content

Commit

Permalink
fix: align job object in job handler
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Aug 9, 2023
1 parent 76cd2b8 commit d33ea04
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/api/src/handlers/job.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { BullBoardRequest, ControllerHandlerReturnType, QueueJob } from '../../typings/app';
import { queueProvider } from '../providers/queue';
import { jobProvider } from '../providers/job';
import { BaseAdapter } from '../queueAdapters/base';
import { formatJob } from './queues';

async function getJobState(
_req: BullBoardRequest,
job: QueueJob
job: QueueJob,
queue: BaseAdapter
): Promise<ControllerHandlerReturnType> {
const status = await job.getState();

return {
status: 200,
body: {
job,
job: formatJob(job, queue),
status,
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/handlers/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { STATUSES } from '../constants/statuses';
import { BaseAdapter } from '../queueAdapters/base';

const formatJob = (job: QueueJob, queue: BaseAdapter): AppJob => {
export const formatJob = (job: QueueJob, queue: BaseAdapter): AppJob => {
const jobProps = job.toJSON();

const stacktrace = jobProps.stacktrace ? jobProps.stacktrace.filter(Boolean) : [];
Expand Down
8 changes: 6 additions & 2 deletions packages/api/src/providers/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { BullBoardRequest, ControllerHandlerReturnType, QueueJob } from '../../t
import { BaseAdapter } from '../queueAdapters/base';

export function jobProvider(
next: (req: BullBoardRequest, job: QueueJob) => Promise<ControllerHandlerReturnType>
next: (
req: BullBoardRequest,
job: QueueJob,
queue: BaseAdapter
) => Promise<ControllerHandlerReturnType>
) {
return async (
req: BullBoardRequest,
Expand All @@ -21,6 +25,6 @@ export function jobProvider(
};
}

return next(req, job);
return next(req, job, queue);
};
}

0 comments on commit d33ea04

Please sign in to comment.