Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
feat(gql): processingTime Job field
Browse files Browse the repository at this point in the history
  • Loading branch information
s-r-x committed Jul 27, 2021
1 parent 3ac8400 commit 841fb7e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/root/src/gql/data-sources/bull/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export class BullDataSource extends DataSource {
}
return job;
}
extractJobProcessingTime(job: Job): number {
if (!job.processedOn || !job.finishedOn) return 0;
return job.finishedOn - job.processedOn;
}
async getJobLogs(queueName: string, id: number) {
const queue = this.getQueueByName(queueName, true);
return await queue?.getJobLogs(id);
Expand Down
3 changes: 3 additions & 0 deletions packages/root/src/gql/resolvers/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export const JobResolver: TResolvers = {
delay({ opts }: BullJob) {
return opts.delay;
},
processingTime(job: BullJob, _vars, { dataSources: { bull } }) {
return bull.extractJobProcessingTime(job);
},
logs(job: BullJob, _vars, { dataSources: { bull } }) {
return bull.getJobLogs(job.queue.name, job.id as number);
},
Expand Down
1 change: 1 addition & 0 deletions packages/root/src/gql/type-defs/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const jobTypeDef = gql`
timestamp: Float!
finishedOn: Float
processedOn: Float
processingTime: Float
opts: String!
}
`;
2 changes: 2 additions & 0 deletions packages/root/src/typings/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type Job = {
timestamp: Scalars['Float'];
finishedOn?: Maybe<Scalars['Float']>;
processedOn?: Maybe<Scalars['Float']>;
processingTime?: Maybe<Scalars['Float']>;
opts: Scalars['String'];
};

Expand Down Expand Up @@ -270,6 +271,7 @@ export type QueryJobArgs = {

export type Queue = {
name: Scalars['String'];
keyPrefix?: Maybe<Scalars['String']>;
/** https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queuecount */
count: Scalars['Int'];
/** https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queuegetjobcounts */
Expand Down

0 comments on commit 841fb7e

Please sign in to comment.