Skip to content

Commit

Permalink
fix(queueevents): add active type fixes #519
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored May 5, 2021
1 parent 5770aef commit 10af883
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/classes/queue-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { QueueBase } from './queue-base';
import { StreamReadRaw } from '../interfaces/redis-streams';

export declare interface QueueEvents {
on(
event: 'active',
listener: (args: { jobId: string }, prev?: string) => void,
): this;
on(
event: 'waiting',
listener: (args: { jobId: string }, id: string) => void,
Expand Down
10 changes: 5 additions & 5 deletions src/test/test_delay.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Queue, Job } from '@src/classes';
import { Queue, Job } from '../classes';
import { describe, beforeEach, it } from 'mocha';
import { expect } from 'chai';
import * as IORedis from 'ioredis';
import { v4 } from 'uuid';
import { Worker } from '@src/classes/worker';
import { QueueEvents } from '@src/classes/queue-events';
import { QueueScheduler } from '@src/classes/queue-scheduler';
import { removeAllQueueData } from '@src/utils';
import { Worker } from '../classes/worker';
import { QueueEvents } from '../classes/queue-events';
import { QueueScheduler } from '../classes/queue-scheduler';
import { removeAllQueueData } from '../utils';

describe('Delayed jobs', function() {
this.timeout(15000);
Expand Down
11 changes: 8 additions & 3 deletions src/test/test_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,22 @@ describe('events', function() {

let state: string;
await delay(50); // additional delay since XREAD from '$' is unstable
queueEvents.on('waiting', function() {
queueEvents.on('waiting', function({ jobId }) {
expect(jobId).to.be.equal('1');
expect(state).to.be.undefined;
state = 'waiting';
});
queueEvents.once('active', function() {
queueEvents.once('active', function({ jobId, prev }) {
expect(jobId).to.be.equal('1');
expect(prev).to.be.equal('waiting');
expect(state).to.be.equal('waiting');
state = 'active';
});

const completed = new Promise(resolve => {
queueEvents.once('completed', async function() {
queueEvents.once('completed', async function({ jobId, returnvalue }) {
expect(jobId).to.be.equal('1');
expect(returnvalue).to.be.null;
expect(state).to.be.equal('active');
resolve();
});
Expand Down

0 comments on commit 10af883

Please sign in to comment.