From 011b8acfdec54737d94a9fead2423e060e3364db Mon Sep 17 00:00:00 2001 From: Manuel Astudillo Date: Fri, 10 Apr 2020 13:37:47 +0200 Subject: [PATCH] fix(scheduler): duplicate connections fixes #174 --- src/classes/queue-scheduler.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/classes/queue-scheduler.ts b/src/classes/queue-scheduler.ts index e14d2855f9..7b745a2157 100644 --- a/src/classes/queue-scheduler.ts +++ b/src/classes/queue-scheduler.ts @@ -1,5 +1,5 @@ import { QueueSchedulerOptions } from '../interfaces'; -import { array2obj } from '../utils'; +import { array2obj, isRedisInstance } from '../utils'; import { QueueBase } from './'; import { Scripts } from './scripts'; import IORedis = require('ioredis'); @@ -26,8 +26,18 @@ export class QueueScheduler extends QueueBase { private nextTimestamp = Number.MAX_VALUE; private isBlocked = false; - constructor(name: string, opts: QueueSchedulerOptions = {}) { - super(name, { maxStalledCount: 1, stalledInterval: 30000, ...opts }); + constructor( + name: string, + { connection, ...opts }: QueueSchedulerOptions = {}, + ) { + super(name, { + maxStalledCount: 1, + stalledInterval: 30000, + ...opts, + connection: isRedisInstance(connection) + ? (connection).duplicate() + : connection, + }); // tslint:disable: no-floating-promises this.run();