From c7462cacf22e04eb707aeaa1c2c4321d13a06f82 Mon Sep 17 00:00:00 2001 From: Robert D'Ercole Date: Mon, 10 Feb 2020 13:00:25 -0500 Subject: [PATCH 1/2] fix: modified imports to work when esModuleInterop is disabled https://github.com/taskforcesh/bullmq/issues/129 --- src/classes/child-pool.ts | 9 ++++----- src/classes/job.ts | 8 ++++---- src/classes/redis-connection.ts | 14 +++++++------- src/classes/timer-manager.ts | 2 +- src/classes/worker.ts | 10 +++++----- src/commands/index.ts | 4 ++-- src/interfaces/queue-options.ts | 4 ++-- src/interfaces/redis-options.ts | 6 +++--- src/test/test_bulk.ts | 4 ++-- src/test/test_clean.ts | 6 +++--- src/test/test_compat.ts | 8 ++++---- src/test/test_connection.ts | 4 ++-- src/test/test_delay.ts | 4 ++-- src/test/test_events.ts | 8 ++++---- src/test/test_getters.ts | 4 ++-- src/test/test_job.ts | 4 ++-- src/test/test_pause.ts | 4 ++-- src/test/test_queue.ts | 6 +++--- src/test/test_rate_limiter.ts | 4 ++-- src/test/test_repeat.ts | 4 ++-- src/test/test_sandboxed_process.ts | 4 ++-- src/test/test_stalled_jobs.ts | 4 ++-- src/test/test_worker.ts | 4 ++-- src/utils.ts | 4 ++-- tsconfig.json | 4 ++-- 25 files changed, 68 insertions(+), 69 deletions(-) diff --git a/src/classes/child-pool.ts b/src/classes/child-pool.ts index 59409b01c4..75fb1d1873 100644 --- a/src/classes/child-pool.ts +++ b/src/classes/child-pool.ts @@ -1,12 +1,11 @@ -import childProcess, { ChildProcess } from 'child_process'; -import path from 'path'; +import { ChildProcess, fork } from 'child_process'; +import * as path from 'path'; import { forEach, values, flatten } from 'lodash'; -import getPort from 'get-port'; -import fs from 'fs'; +import * as getPort from 'get-port'; +import * as fs from 'fs'; import { promisify } from 'util'; const stat = promisify(fs.stat); -const fork = childProcess.fork; export interface ChildProcessExt extends ChildProcess { processFile?: string; diff --git a/src/classes/job.ts b/src/classes/job.ts index b8170dbacb..f928e416fb 100644 --- a/src/classes/job.ts +++ b/src/classes/job.ts @@ -1,4 +1,4 @@ -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { debuglog } from 'util'; import { RetryErrors } from '../enums'; import { BackoffOptions, JobsOptions, WorkerOptions } from '../interfaces'; @@ -92,7 +92,7 @@ export class Job { const multi = client.multi(); for (const job of jobInstances) { - job.addJob((multi as unknown)); + job.addJob((multi as unknown)); } const result = (await multi.exec()) as [null | Error, string][]; @@ -454,7 +454,7 @@ export class Job { ); } - private addJob(client: IORedis.Redis): string { + private addJob(client: Redis.Redis): string { const queue = this.queue; const jobData = this.asJSON(); @@ -462,7 +462,7 @@ export class Job { return Scripts.addJob(client, queue, jobData, this.opts, this.id); } - private saveAttempt(multi: IORedis.Pipeline, err: Error) { + private saveAttempt(multi: Redis.Pipeline, err: Error) { this.attemptsMade++; this.stacktrace = this.stacktrace || []; diff --git a/src/classes/redis-connection.ts b/src/classes/redis-connection.ts index 7021126be4..7fe13932af 100644 --- a/src/classes/redis-connection.ts +++ b/src/classes/redis-connection.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events'; -import IORedis, { Redis } from 'ioredis'; +import * as Redis from 'ioredis'; import * as semver from 'semver'; import { load } from '../commands'; import { ConnectionOptions, RedisOptions } from '../interfaces'; @@ -7,8 +7,8 @@ import { isRedisInstance } from '../utils'; export class RedisConnection extends EventEmitter { static minimumVersion = '5.0.0'; - private _client: Redis; - private initializing: Promise; + private _client: Redis.Redis; + private initializing: Promise; private closing: boolean; constructor(private opts?: ConnectionOptions) { @@ -24,7 +24,7 @@ export class RedisConnection extends EventEmitter { ...opts, }; } else { - this._client = opts; + this._client = opts; } this.initializing = this.init(); @@ -38,7 +38,7 @@ export class RedisConnection extends EventEmitter { * Waits for a redis client to be ready. * @param {Redis} redis client */ - static async waitUntilReady(client: IORedis.Redis) { + static async waitUntilReady(client: Redis.Redis) { return new Promise(function(resolve, reject) { if (client.status === 'ready') { resolve(); @@ -60,14 +60,14 @@ export class RedisConnection extends EventEmitter { }); } - get client(): Promise { + get client(): Promise { return this.initializing; } private async init() { const opts = this.opts as RedisOptions; if (!this._client) { - this._client = new IORedis(opts); + this._client = new Redis(opts); } await RedisConnection.waitUntilReady(this._client); diff --git a/src/classes/timer-manager.ts b/src/classes/timer-manager.ts index 44bde84a7f..5a38c8b057 100644 --- a/src/classes/timer-manager.ts +++ b/src/classes/timer-manager.ts @@ -1,4 +1,4 @@ -import uuid from 'uuid'; +import * as uuid from 'uuid'; /** * Keeps track on timers created with setTimeout to help clearTimeout diff --git a/src/classes/worker.ts b/src/classes/worker.ts index 9ab8be7ead..efccef7af1 100644 --- a/src/classes/worker.ts +++ b/src/classes/worker.ts @@ -1,6 +1,6 @@ -import fs from 'fs'; -import { Redis } from 'ioredis'; -import path from 'path'; +import * as fs from 'fs'; +import * as Redis from 'ioredis'; +import * as path from 'path'; import { Processor, WorkerOptions } from '../interfaces'; import { QueueBase, Repeat } from './'; import { ChildPool, pool } from './child-pool'; @@ -8,7 +8,7 @@ import { Job } from './job'; import { RedisConnection } from './redis-connection'; import sandbox from './sandbox'; import { Scripts } from './scripts'; -import uuid from 'uuid'; +import * as uuid from 'uuid'; import { TimerManager } from './timer-manager'; import { isRedisInstance } from '../utils'; @@ -53,7 +53,7 @@ export class Worker extends QueueBase { this.blockingConnection = new RedisConnection( isRedisInstance(opts.connection) - ? (opts.connection).duplicate() + ? (opts.connection).duplicate() : opts.connection, ); this.blockingConnection.on('error', this.emit.bind(this)); diff --git a/src/commands/index.ts b/src/commands/index.ts index 53f9c81bd8..2791370deb 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -12,7 +12,7 @@ */ 'use strict'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; const path = require('path'); const util = require('util'); @@ -30,7 +30,7 @@ interface Command { }; } -export const load = async function(client: IORedis.Redis) { +export const load = async function(client: Redis.Redis) { const scripts = await loadScripts(__dirname); scripts.forEach((command: Command) => { diff --git a/src/interfaces/queue-options.ts b/src/interfaces/queue-options.ts index 8aef15c8dd..0313463479 100644 --- a/src/interfaces/queue-options.ts +++ b/src/interfaces/queue-options.ts @@ -1,6 +1,6 @@ import { JobsOptions } from '../interfaces'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { ConnectionOptions } from './redis-options'; export enum ClientType { @@ -10,7 +10,7 @@ export enum ClientType { export interface QueueBaseOptions { connection?: ConnectionOptions; - client?: IORedis.Redis; + client?: Redis.Redis; prefix?: string; // prefix for all queue keys. } diff --git a/src/interfaces/redis-options.ts b/src/interfaces/redis-options.ts index 52c23639f7..c85fdde6ab 100644 --- a/src/interfaces/redis-options.ts +++ b/src/interfaces/redis-options.ts @@ -1,7 +1,7 @@ -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; -export type RedisOptions = IORedis.RedisOptions & { +export type RedisOptions = Redis.RedisOptions & { skipVersionCheck?: boolean; }; -export type ConnectionOptions = RedisOptions | IORedis.Redis; +export type ConnectionOptions = RedisOptions | Redis.Redis; diff --git a/src/test/test_bulk.ts b/src/test/test_bulk.ts index dcc6530285..89cf5cf13d 100644 --- a/src/test/test_bulk.ts +++ b/src/test/test_bulk.ts @@ -1,6 +1,6 @@ import { Queue, Worker, Job } from '../classes'; import { expect } from 'chai'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; import { removeAllQueueData } from '../utils'; @@ -16,7 +16,7 @@ describe('bulk jobs', () => { afterEach(async function() { await queue.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('should process jobs', async () => { diff --git a/src/test/test_clean.ts b/src/test/test_clean.ts index d3bd5a66cc..8f04d44a5f 100644 --- a/src/test/test_clean.ts +++ b/src/test/test_clean.ts @@ -1,7 +1,7 @@ import { Queue, QueueEvents, Worker } from '../classes'; import { delay, removeAllQueueData } from '@src/utils'; import { expect } from 'chai'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { after } from 'lodash'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; @@ -21,7 +21,7 @@ describe('Cleaner', () => { afterEach(async function() { await queue.close(); await queueEvents.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('should clean an empty queue', async () => { @@ -127,7 +127,7 @@ describe('Cleaner', () => { }); await worker.waitUntilReady(); - const client = new IORedis(); + const client = new Redis(); await queue.add('test', { some: 'data' }); await queue.add('test', { some: 'data' }); diff --git a/src/test/test_compat.ts b/src/test/test_compat.ts index 862c6f9e21..4bee673421 100644 --- a/src/test/test_compat.ts +++ b/src/test/test_compat.ts @@ -6,7 +6,7 @@ import { Job, Worker } from '@src/classes'; import { Queue3 } from '@src/classes/compat'; import { delay, removeAllQueueData } from '@src/utils'; import { expect } from 'chai'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { after } from 'lodash'; import { afterEach, beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; @@ -24,7 +24,7 @@ describe('Compat', function() { afterEach(async function() { await queue.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('should get waiting jobs', async function() { @@ -294,7 +294,7 @@ describe('Compat', function() { afterEach(async function() { await queue.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('should emit waiting when a job has been added', function(done) { @@ -403,7 +403,7 @@ describe('Compat', function() { afterEach(async function() { await queue.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); // it('should pause a queue until resumed', async () => { diff --git a/src/test/test_connection.ts b/src/test/test_connection.ts index 0836e8e011..bd9c5e8d57 100644 --- a/src/test/test_connection.ts +++ b/src/test/test_connection.ts @@ -1,4 +1,4 @@ -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { Queue, QueueEvents, Job, Worker } from '@src/classes'; import { v4 } from 'uuid'; @@ -16,7 +16,7 @@ describe('connection', () => { afterEach(async () => { await queue.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('should recover from a connection loss', async () => { diff --git a/src/test/test_delay.ts b/src/test/test_delay.ts index 17254cfe60..9303f4adcf 100644 --- a/src/test/test_delay.ts +++ b/src/test/test_delay.ts @@ -1,7 +1,7 @@ import { Queue, Job } from '@src/classes'; import { describe, beforeEach, it } from 'mocha'; import { expect } from 'chai'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { v4 } from 'uuid'; import { Worker } from '@src/classes/worker'; import { QueueEvents } from '@src/classes/queue-events'; @@ -21,7 +21,7 @@ describe('Delayed jobs', function() { afterEach(async function() { await queue.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('should process a delayed job only after delayed time', async function() { diff --git a/src/test/test_events.ts b/src/test/test_events.ts index 10bff3154f..1c0572ced3 100644 --- a/src/test/test_events.ts +++ b/src/test/test_events.ts @@ -2,7 +2,7 @@ import { Queue } from '@src/classes'; import { QueueEvents } from '@src/classes/queue-events'; import { Worker } from '@src/classes/worker'; import { expect } from 'chai'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; import { delay, removeAllQueueData } from '@src/utils'; @@ -23,7 +23,7 @@ describe('events', function() { afterEach(async function() { await queue.close(); await queueEvents.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('should emit waiting when a job has been added', async function() { @@ -169,7 +169,7 @@ describe('events', function() { expect(eventsLength).to.be.equal(1); await trimmedQueue.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('should trim events manually', async () => { @@ -194,6 +194,6 @@ describe('events', function() { expect(eventsLength).to.be.equal(0); await trimmedQueue.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); }); diff --git a/src/test/test_getters.ts b/src/test/test_getters.ts index 5983acbad6..76e67c35c6 100644 --- a/src/test/test_getters.ts +++ b/src/test/test_getters.ts @@ -5,7 +5,7 @@ import { Queue, Job } from '@src/classes'; import { describe, beforeEach, it } from 'mocha'; import { expect } from 'chai'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { v4 } from 'uuid'; import { Worker } from '@src/classes/worker'; import { after } from 'lodash'; @@ -23,7 +23,7 @@ describe('Jobs getters', function() { afterEach(async function() { await queue.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('should get waiting jobs', async function() { diff --git a/src/test/test_job.ts b/src/test/test_job.ts index 4a6d2928a4..164572c2a1 100644 --- a/src/test/test_job.ts +++ b/src/test/test_job.ts @@ -7,7 +7,7 @@ import { Worker } from '@src/classes/worker'; import { JobsOptions } from '@src/interfaces'; import { delay, removeAllQueueData } from '@src/utils'; import { expect } from 'chai'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { after } from 'lodash'; import { afterEach, beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; @@ -23,7 +23,7 @@ describe('Job', function() { afterEach(async () => { await queue.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); describe('.create', function() { diff --git a/src/test/test_pause.ts b/src/test/test_pause.ts index 655e675bc2..8f9e9dfe6e 100644 --- a/src/test/test_pause.ts +++ b/src/test/test_pause.ts @@ -2,7 +2,7 @@ import { Job, Queue } from '@src/classes'; import { QueueEvents, QueueScheduler } from '../classes'; import { Worker } from '@src/classes/worker'; import { expect } from 'chai'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; import { delay, removeAllQueueData } from '@src/utils'; @@ -22,7 +22,7 @@ describe('Pause', function() { afterEach(async function() { await queue.close(); await queueEvents.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); // Skipped since some side effect makes this test fail diff --git a/src/test/test_queue.ts b/src/test/test_queue.ts index e8368a1e58..5716f179d1 100644 --- a/src/test/test_queue.ts +++ b/src/test/test_queue.ts @@ -2,7 +2,7 @@ import { Queue } from '@src/classes'; import { describe, beforeEach, it } from 'mocha'; import { expect, assert } from 'chai'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { v4 } from 'uuid'; import { Worker } from '@src/classes/worker'; import { after } from 'lodash'; @@ -15,7 +15,7 @@ describe('Queue', function() { let queueEvents: QueueEvents; beforeEach(function() { - client = new IORedis(); + client = new Redis(); }); beforeEach(async function() { @@ -28,7 +28,7 @@ describe('Queue', function() { afterEach(async function() { await queue.close(); await queueEvents.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('creates a queue with default job options', () => { diff --git a/src/test/test_rate_limiter.ts b/src/test/test_rate_limiter.ts index c42ff7ae79..4df770c77a 100644 --- a/src/test/test_rate_limiter.ts +++ b/src/test/test_rate_limiter.ts @@ -3,7 +3,7 @@ import { QueueEvents } from '@src/classes/queue-events'; import { QueueScheduler } from '@src/classes/queue-scheduler'; import { Worker } from '@src/classes/worker'; import { assert, expect } from 'chai'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { after } from 'lodash'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; @@ -24,7 +24,7 @@ describe('Rate Limiter', function() { afterEach(async function() { await queue.close(); await queueEvents.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('should put a job into the delayed queue when limit is hit', async () => { diff --git a/src/test/test_repeat.ts b/src/test/test_repeat.ts index faa57cb165..651ad08002 100644 --- a/src/test/test_repeat.ts +++ b/src/test/test_repeat.ts @@ -4,7 +4,7 @@ import { QueueScheduler } from '@src/classes/queue-scheduler'; import { Repeat } from '@src/classes/repeat'; import { Worker } from '@src/classes/worker'; import { expect } from 'chai'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; import { defaults } from 'lodash'; @@ -45,7 +45,7 @@ describe('repeat', function() { await queue.close(); await repeat.close(); await queueEvents.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('should create multiple jobs if they have the same cron pattern', async function() { diff --git a/src/test/test_sandboxed_process.ts b/src/test/test_sandboxed_process.ts index 381837a292..291f4afc8d 100644 --- a/src/test/test_sandboxed_process.ts +++ b/src/test/test_sandboxed_process.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { after } from 'lodash'; import { Queue, QueueEvents, Worker, pool } from '@src/classes'; import { beforeEach } from 'mocha'; @@ -23,7 +23,7 @@ describe('sandboxed process', () => { await queue.close(); await queueEvents.close(); pool.clean(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('should process and complete', async () => { diff --git a/src/test/test_stalled_jobs.ts b/src/test/test_stalled_jobs.ts index 7cbeb31300..3dfce64046 100644 --- a/src/test/test_stalled_jobs.ts +++ b/src/test/test_stalled_jobs.ts @@ -1,6 +1,6 @@ import { Queue, QueueScheduler, Worker, QueueEvents } from '@src/classes'; import { delay, removeAllQueueData } from '@src/utils'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { after } from 'lodash'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; @@ -17,7 +17,7 @@ describe('stalled jobs', function() { afterEach(async function() { await queue.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('process stalled jobs when starting a queue', async function() { diff --git a/src/test/test_worker.ts b/src/test/test_worker.ts index 11fdae5886..4fe30ce01c 100644 --- a/src/test/test_worker.ts +++ b/src/test/test_worker.ts @@ -1,7 +1,7 @@ import { Queue, QueueEvents, Job, Worker, QueueScheduler } from '@src/classes'; import { describe, beforeEach, it } from 'mocha'; import { expect } from 'chai'; -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; import { v4 } from 'uuid'; import { delay, removeAllQueueData } from '@src/utils'; import { after, times, once } from 'lodash'; @@ -26,7 +26,7 @@ describe('workers', function() { sandbox.restore(); await queue.close(); await queueEvents.close(); - await removeAllQueueData(new IORedis(), queueName); + await removeAllQueueData(new Redis(), queueName); }); it('should get all workers for this queue', async function() { diff --git a/src/utils.ts b/src/utils.ts index 0b2e39fd5c..e3d554b380 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import IORedis from 'ioredis'; +import * as Redis from 'ioredis'; export const errorObject: { [index: string]: any } = { value: null }; @@ -43,7 +43,7 @@ export function isRedisInstance(obj: any): boolean { } export async function removeAllQueueData( - client: IORedis.Redis, + client: Redis.Redis, queueName: string, prefix = 'bull', ) { diff --git a/tsconfig.json b/tsconfig.json index 189342c836..90fa0de4e8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,8 +11,8 @@ "jsx": "preserve", "importHelpers": true, "moduleResolution": "node", - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, + "esModuleInterop": false, + "allowSyntheticDefaultImports": false, "strictNullChecks": false, "baseUrl": ".", "paths": { From 892e82f4acf25ef7f2584ae1cbf1feb030beac65 Mon Sep 17 00:00:00 2001 From: Robert D'Ercole Date: Tue, 11 Feb 2020 10:33:42 -0500 Subject: [PATCH 2/2] refactor: converted all ioredis imports to named imports where possible --- src/classes/job.ts | 8 ++++---- src/classes/redis-connection.ts | 14 +++++++------- src/classes/worker.ts | 4 ++-- src/commands/index.ts | 4 ++-- src/interfaces/queue-options.ts | 4 ++-- src/interfaces/redis-options.ts | 6 +++--- src/test/test_bulk.ts | 4 ++-- src/test/test_clean.ts | 6 +++--- src/test/test_compat.ts | 8 ++++---- src/test/test_connection.ts | 4 ++-- src/test/test_delay.ts | 4 ++-- src/test/test_events.ts | 8 ++++---- src/test/test_getters.ts | 4 ++-- src/test/test_job.ts | 4 ++-- src/test/test_pause.ts | 4 ++-- src/test/test_queue.ts | 6 +++--- src/test/test_rate_limiter.ts | 4 ++-- src/test/test_repeat.ts | 4 ++-- src/test/test_sandboxed_process.ts | 4 ++-- src/test/test_stalled_jobs.ts | 4 ++-- src/test/test_worker.ts | 4 ++-- src/utils.ts | 4 ++-- 22 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/classes/job.ts b/src/classes/job.ts index f928e416fb..b2140994a8 100644 --- a/src/classes/job.ts +++ b/src/classes/job.ts @@ -1,4 +1,4 @@ -import * as Redis from 'ioredis'; +import { Redis, Pipeline } from 'ioredis'; import { debuglog } from 'util'; import { RetryErrors } from '../enums'; import { BackoffOptions, JobsOptions, WorkerOptions } from '../interfaces'; @@ -92,7 +92,7 @@ export class Job { const multi = client.multi(); for (const job of jobInstances) { - job.addJob((multi as unknown)); + job.addJob((multi as unknown)); } const result = (await multi.exec()) as [null | Error, string][]; @@ -454,7 +454,7 @@ export class Job { ); } - private addJob(client: Redis.Redis): string { + private addJob(client: Redis): string { const queue = this.queue; const jobData = this.asJSON(); @@ -462,7 +462,7 @@ export class Job { return Scripts.addJob(client, queue, jobData, this.opts, this.id); } - private saveAttempt(multi: Redis.Pipeline, err: Error) { + private saveAttempt(multi: Pipeline, err: Error) { this.attemptsMade++; this.stacktrace = this.stacktrace || []; diff --git a/src/classes/redis-connection.ts b/src/classes/redis-connection.ts index 7fe13932af..768fffcdf4 100644 --- a/src/classes/redis-connection.ts +++ b/src/classes/redis-connection.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import * as semver from 'semver'; import { load } from '../commands'; import { ConnectionOptions, RedisOptions } from '../interfaces'; @@ -7,8 +7,8 @@ import { isRedisInstance } from '../utils'; export class RedisConnection extends EventEmitter { static minimumVersion = '5.0.0'; - private _client: Redis.Redis; - private initializing: Promise; + private _client: IORedis.Redis; + private initializing: Promise; private closing: boolean; constructor(private opts?: ConnectionOptions) { @@ -24,7 +24,7 @@ export class RedisConnection extends EventEmitter { ...opts, }; } else { - this._client = opts; + this._client = opts; } this.initializing = this.init(); @@ -38,7 +38,7 @@ export class RedisConnection extends EventEmitter { * Waits for a redis client to be ready. * @param {Redis} redis client */ - static async waitUntilReady(client: Redis.Redis) { + static async waitUntilReady(client: IORedis.Redis) { return new Promise(function(resolve, reject) { if (client.status === 'ready') { resolve(); @@ -60,14 +60,14 @@ export class RedisConnection extends EventEmitter { }); } - get client(): Promise { + get client(): Promise { return this.initializing; } private async init() { const opts = this.opts as RedisOptions; if (!this._client) { - this._client = new Redis(opts); + this._client = new IORedis(opts); } await RedisConnection.waitUntilReady(this._client); diff --git a/src/classes/worker.ts b/src/classes/worker.ts index efccef7af1..a97729c412 100644 --- a/src/classes/worker.ts +++ b/src/classes/worker.ts @@ -1,5 +1,5 @@ import * as fs from 'fs'; -import * as Redis from 'ioredis'; +import { Redis } from 'ioredis'; import * as path from 'path'; import { Processor, WorkerOptions } from '../interfaces'; import { QueueBase, Repeat } from './'; @@ -53,7 +53,7 @@ export class Worker extends QueueBase { this.blockingConnection = new RedisConnection( isRedisInstance(opts.connection) - ? (opts.connection).duplicate() + ? (opts.connection).duplicate() : opts.connection, ); this.blockingConnection.on('error', this.emit.bind(this)); diff --git a/src/commands/index.ts b/src/commands/index.ts index 2791370deb..acd14e3a05 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -12,7 +12,7 @@ */ 'use strict'; -import * as Redis from 'ioredis'; +import { Redis } from 'ioredis'; const path = require('path'); const util = require('util'); @@ -30,7 +30,7 @@ interface Command { }; } -export const load = async function(client: Redis.Redis) { +export const load = async function(client: Redis) { const scripts = await loadScripts(__dirname); scripts.forEach((command: Command) => { diff --git a/src/interfaces/queue-options.ts b/src/interfaces/queue-options.ts index 0313463479..4dec999f18 100644 --- a/src/interfaces/queue-options.ts +++ b/src/interfaces/queue-options.ts @@ -1,6 +1,6 @@ import { JobsOptions } from '../interfaces'; -import * as Redis from 'ioredis'; +import { Redis } from 'ioredis'; import { ConnectionOptions } from './redis-options'; export enum ClientType { @@ -10,7 +10,7 @@ export enum ClientType { export interface QueueBaseOptions { connection?: ConnectionOptions; - client?: Redis.Redis; + client?: Redis; prefix?: string; // prefix for all queue keys. } diff --git a/src/interfaces/redis-options.ts b/src/interfaces/redis-options.ts index c85fdde6ab..23d6c81cde 100644 --- a/src/interfaces/redis-options.ts +++ b/src/interfaces/redis-options.ts @@ -1,7 +1,7 @@ -import * as Redis from 'ioredis'; +import { Redis, RedisOptions as BaseRedisOptions } from 'ioredis'; -export type RedisOptions = Redis.RedisOptions & { +export type RedisOptions = BaseRedisOptions & { skipVersionCheck?: boolean; }; -export type ConnectionOptions = RedisOptions | Redis.Redis; +export type ConnectionOptions = RedisOptions | Redis; diff --git a/src/test/test_bulk.ts b/src/test/test_bulk.ts index 89cf5cf13d..11f63dbf7b 100644 --- a/src/test/test_bulk.ts +++ b/src/test/test_bulk.ts @@ -1,6 +1,6 @@ import { Queue, Worker, Job } from '../classes'; import { expect } from 'chai'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; import { removeAllQueueData } from '../utils'; @@ -16,7 +16,7 @@ describe('bulk jobs', () => { afterEach(async function() { await queue.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('should process jobs', async () => { diff --git a/src/test/test_clean.ts b/src/test/test_clean.ts index 8f04d44a5f..e07d47e6b4 100644 --- a/src/test/test_clean.ts +++ b/src/test/test_clean.ts @@ -1,7 +1,7 @@ import { Queue, QueueEvents, Worker } from '../classes'; import { delay, removeAllQueueData } from '@src/utils'; import { expect } from 'chai'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { after } from 'lodash'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; @@ -21,7 +21,7 @@ describe('Cleaner', () => { afterEach(async function() { await queue.close(); await queueEvents.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('should clean an empty queue', async () => { @@ -127,7 +127,7 @@ describe('Cleaner', () => { }); await worker.waitUntilReady(); - const client = new Redis(); + const client = new IORedis(); await queue.add('test', { some: 'data' }); await queue.add('test', { some: 'data' }); diff --git a/src/test/test_compat.ts b/src/test/test_compat.ts index 4bee673421..dd58b8fb37 100644 --- a/src/test/test_compat.ts +++ b/src/test/test_compat.ts @@ -6,7 +6,7 @@ import { Job, Worker } from '@src/classes'; import { Queue3 } from '@src/classes/compat'; import { delay, removeAllQueueData } from '@src/utils'; import { expect } from 'chai'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { after } from 'lodash'; import { afterEach, beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; @@ -24,7 +24,7 @@ describe('Compat', function() { afterEach(async function() { await queue.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('should get waiting jobs', async function() { @@ -294,7 +294,7 @@ describe('Compat', function() { afterEach(async function() { await queue.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('should emit waiting when a job has been added', function(done) { @@ -403,7 +403,7 @@ describe('Compat', function() { afterEach(async function() { await queue.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); // it('should pause a queue until resumed', async () => { diff --git a/src/test/test_connection.ts b/src/test/test_connection.ts index bd9c5e8d57..f9bb4320e3 100644 --- a/src/test/test_connection.ts +++ b/src/test/test_connection.ts @@ -1,4 +1,4 @@ -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { Queue, QueueEvents, Job, Worker } from '@src/classes'; import { v4 } from 'uuid'; @@ -16,7 +16,7 @@ describe('connection', () => { afterEach(async () => { await queue.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('should recover from a connection loss', async () => { diff --git a/src/test/test_delay.ts b/src/test/test_delay.ts index 9303f4adcf..3ef41746ad 100644 --- a/src/test/test_delay.ts +++ b/src/test/test_delay.ts @@ -1,7 +1,7 @@ import { Queue, Job } from '@src/classes'; import { describe, beforeEach, it } from 'mocha'; import { expect } from 'chai'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { v4 } from 'uuid'; import { Worker } from '@src/classes/worker'; import { QueueEvents } from '@src/classes/queue-events'; @@ -21,7 +21,7 @@ describe('Delayed jobs', function() { afterEach(async function() { await queue.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('should process a delayed job only after delayed time', async function() { diff --git a/src/test/test_events.ts b/src/test/test_events.ts index 1c0572ced3..fed6ccb4a8 100644 --- a/src/test/test_events.ts +++ b/src/test/test_events.ts @@ -2,7 +2,7 @@ import { Queue } from '@src/classes'; import { QueueEvents } from '@src/classes/queue-events'; import { Worker } from '@src/classes/worker'; import { expect } from 'chai'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; import { delay, removeAllQueueData } from '@src/utils'; @@ -23,7 +23,7 @@ describe('events', function() { afterEach(async function() { await queue.close(); await queueEvents.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('should emit waiting when a job has been added', async function() { @@ -169,7 +169,7 @@ describe('events', function() { expect(eventsLength).to.be.equal(1); await trimmedQueue.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('should trim events manually', async () => { @@ -194,6 +194,6 @@ describe('events', function() { expect(eventsLength).to.be.equal(0); await trimmedQueue.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); }); diff --git a/src/test/test_getters.ts b/src/test/test_getters.ts index 76e67c35c6..2b84d81248 100644 --- a/src/test/test_getters.ts +++ b/src/test/test_getters.ts @@ -5,7 +5,7 @@ import { Queue, Job } from '@src/classes'; import { describe, beforeEach, it } from 'mocha'; import { expect } from 'chai'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { v4 } from 'uuid'; import { Worker } from '@src/classes/worker'; import { after } from 'lodash'; @@ -23,7 +23,7 @@ describe('Jobs getters', function() { afterEach(async function() { await queue.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('should get waiting jobs', async function() { diff --git a/src/test/test_job.ts b/src/test/test_job.ts index 164572c2a1..4db8c140d3 100644 --- a/src/test/test_job.ts +++ b/src/test/test_job.ts @@ -7,7 +7,7 @@ import { Worker } from '@src/classes/worker'; import { JobsOptions } from '@src/interfaces'; import { delay, removeAllQueueData } from '@src/utils'; import { expect } from 'chai'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { after } from 'lodash'; import { afterEach, beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; @@ -23,7 +23,7 @@ describe('Job', function() { afterEach(async () => { await queue.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); describe('.create', function() { diff --git a/src/test/test_pause.ts b/src/test/test_pause.ts index 8f9e9dfe6e..d70dfc29fe 100644 --- a/src/test/test_pause.ts +++ b/src/test/test_pause.ts @@ -2,7 +2,7 @@ import { Job, Queue } from '@src/classes'; import { QueueEvents, QueueScheduler } from '../classes'; import { Worker } from '@src/classes/worker'; import { expect } from 'chai'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; import { delay, removeAllQueueData } from '@src/utils'; @@ -22,7 +22,7 @@ describe('Pause', function() { afterEach(async function() { await queue.close(); await queueEvents.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); // Skipped since some side effect makes this test fail diff --git a/src/test/test_queue.ts b/src/test/test_queue.ts index 5716f179d1..56a972e02b 100644 --- a/src/test/test_queue.ts +++ b/src/test/test_queue.ts @@ -2,7 +2,7 @@ import { Queue } from '@src/classes'; import { describe, beforeEach, it } from 'mocha'; import { expect, assert } from 'chai'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { v4 } from 'uuid'; import { Worker } from '@src/classes/worker'; import { after } from 'lodash'; @@ -15,7 +15,7 @@ describe('Queue', function() { let queueEvents: QueueEvents; beforeEach(function() { - client = new Redis(); + client = new IORedis(); }); beforeEach(async function() { @@ -28,7 +28,7 @@ describe('Queue', function() { afterEach(async function() { await queue.close(); await queueEvents.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('creates a queue with default job options', () => { diff --git a/src/test/test_rate_limiter.ts b/src/test/test_rate_limiter.ts index 4df770c77a..87b7014044 100644 --- a/src/test/test_rate_limiter.ts +++ b/src/test/test_rate_limiter.ts @@ -3,7 +3,7 @@ import { QueueEvents } from '@src/classes/queue-events'; import { QueueScheduler } from '@src/classes/queue-scheduler'; import { Worker } from '@src/classes/worker'; import { assert, expect } from 'chai'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { after } from 'lodash'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; @@ -24,7 +24,7 @@ describe('Rate Limiter', function() { afterEach(async function() { await queue.close(); await queueEvents.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('should put a job into the delayed queue when limit is hit', async () => { diff --git a/src/test/test_repeat.ts b/src/test/test_repeat.ts index 651ad08002..71ebe3efbb 100644 --- a/src/test/test_repeat.ts +++ b/src/test/test_repeat.ts @@ -4,7 +4,7 @@ import { QueueScheduler } from '@src/classes/queue-scheduler'; import { Repeat } from '@src/classes/repeat'; import { Worker } from '@src/classes/worker'; import { expect } from 'chai'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; import { defaults } from 'lodash'; @@ -45,7 +45,7 @@ describe('repeat', function() { await queue.close(); await repeat.close(); await queueEvents.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('should create multiple jobs if they have the same cron pattern', async function() { diff --git a/src/test/test_sandboxed_process.ts b/src/test/test_sandboxed_process.ts index 291f4afc8d..59b3f1b594 100644 --- a/src/test/test_sandboxed_process.ts +++ b/src/test/test_sandboxed_process.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { after } from 'lodash'; import { Queue, QueueEvents, Worker, pool } from '@src/classes'; import { beforeEach } from 'mocha'; @@ -23,7 +23,7 @@ describe('sandboxed process', () => { await queue.close(); await queueEvents.close(); pool.clean(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('should process and complete', async () => { diff --git a/src/test/test_stalled_jobs.ts b/src/test/test_stalled_jobs.ts index 3dfce64046..6f16d60e12 100644 --- a/src/test/test_stalled_jobs.ts +++ b/src/test/test_stalled_jobs.ts @@ -1,6 +1,6 @@ import { Queue, QueueScheduler, Worker, QueueEvents } from '@src/classes'; import { delay, removeAllQueueData } from '@src/utils'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { after } from 'lodash'; import { beforeEach, describe, it } from 'mocha'; import { v4 } from 'uuid'; @@ -17,7 +17,7 @@ describe('stalled jobs', function() { afterEach(async function() { await queue.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('process stalled jobs when starting a queue', async function() { diff --git a/src/test/test_worker.ts b/src/test/test_worker.ts index 4fe30ce01c..693b9806d9 100644 --- a/src/test/test_worker.ts +++ b/src/test/test_worker.ts @@ -1,7 +1,7 @@ import { Queue, QueueEvents, Job, Worker, QueueScheduler } from '@src/classes'; import { describe, beforeEach, it } from 'mocha'; import { expect } from 'chai'; -import * as Redis from 'ioredis'; +import * as IORedis from 'ioredis'; import { v4 } from 'uuid'; import { delay, removeAllQueueData } from '@src/utils'; import { after, times, once } from 'lodash'; @@ -26,7 +26,7 @@ describe('workers', function() { sandbox.restore(); await queue.close(); await queueEvents.close(); - await removeAllQueueData(new Redis(), queueName); + await removeAllQueueData(new IORedis(), queueName); }); it('should get all workers for this queue', async function() { diff --git a/src/utils.ts b/src/utils.ts index e3d554b380..88bfda91ec 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import * as Redis from 'ioredis'; +import { Redis } from 'ioredis'; export const errorObject: { [index: string]: any } = { value: null }; @@ -43,7 +43,7 @@ export function isRedisInstance(obj: any): boolean { } export async function removeAllQueueData( - client: Redis.Redis, + client: Redis, queueName: string, prefix = 'bull', ) {