Skip to content

Commit

Permalink
fix: add typings for events
Browse files Browse the repository at this point in the history
  • Loading branch information
simllll committed Oct 13, 2020
1 parent 28df211 commit a6c0356
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/JobProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export class JobProcessor {
version,
queueName: this.agenda.name,
queueSize: await this.agenda.db.getQueueSize(),
config: {
totalLockLimit: this.totalLockLimit,
maxConcurrency: this.maxConcurrency,
processEvery: this.processEvery
},
jobStatus: Object.keys(this.jobStatus).map(job => ({
...this.jobStatus[job],
config: this.agenda.definitions[job]
Expand Down Expand Up @@ -139,6 +144,7 @@ export class JobProcessor {
'job [%s] lock status: shouldLock = %s',
name,
shouldLock,
status?.locked,
this.jobQueue.length,
this.lockedJobs.length,
this.totalLockLimit
Expand Down
14 changes: 14 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ export class Agenda extends EventEmitter {
db: JobDbRepository;
// eslint-disable-next-line default-param-last
// private jobQueue: JobProcessingQueue;
// internally used
on(event: 'processJob', listener: (job: Job) => void): this;

on(event: 'fail', listener: (err: Error, job: Job) => void): this;
on(event: 'success', listener: (job: Job) => void): this;
on(event: 'start', listener: (job: Job) => void): this;
on(event: 'complete', listener: (job: Job) => void): this;
on(event: string, listener: (job: Job) => void): this;
on(event: string, listener: (err: Error, job: Job) => void): this;
on(event: 'ready', listener: () => void): this;
on(event: 'error', listener: (err: Error) => void): this;
on(event, listener) {
return super.on(event, listener);
}

readonly definitions: {
[name: string]: IJobDefinition;
Expand Down
4 changes: 2 additions & 2 deletions test/job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ describe('Job', () => {

const checkResultsPromise = new Promise(resolve =>
agenda.on('start:fifo', job => {
results.push(new Date(job.attrs.nextRunAt).getTime());
results.push(new Date(job.attrs.nextRunAt!).getTime());
if (results.length !== 3) {
return;
}
Expand Down Expand Up @@ -1045,7 +1045,7 @@ describe('Job', () => {
const checkResultsPromise = new Promise(resolve =>
agenda.on('start:fifo-priority', job => {
priorities.push(job.attrs.priority);
times.push(new Date(job.attrs.lastRunAt).getTime());
times.push(new Date(job.attrs.lastRunAt!).getTime());
if (priorities.length !== 3 || times.length !== 3) {
return;
}
Expand Down

0 comments on commit a6c0356

Please sign in to comment.