Skip to content

Commit

Permalink
feat: add isExpired method to Job class
Browse files Browse the repository at this point in the history
  • Loading branch information
code-xhyun committed May 2, 2024
1 parent e5e904e commit 973d0b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/job/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ class Job<T extends JobAttributesData = JobAttributesData> {
return this.bindMethod('isRunning', isRunning);
}

get isExpired(): IsExpiredMethod {
return this.bindMethod('isExpired', isExpired);
}

get save(): SaveMethod {
return this.bindMethod('save', save);
}
Expand Down
16 changes: 16 additions & 0 deletions src/job/is-expired.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Job } from '.';

export type IsExpiredMethod = (useRealStatus?: boolean) => boolean;
export const isExpired: IsExpiredMethod = function (this: Job, useRealStatus = false) {
if (useRealStatus) {
this.fetchStatus();
}
const definition = this.pulse._definitions[this.attrs.name];

const lockDeadline = new Date(Date.now() - definition.lockLifetime);

if (this.attrs.lockedAt && this.attrs.lockedAt < lockDeadline) {
return true;
}
return false;
};

0 comments on commit 973d0b8

Please sign in to comment.