Skip to content

Commit

Permalink
fix(connection): throw error when Upstash host is provided (#1098) fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Feb 24, 2022
1 parent dd1e63c commit 5156d0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/classes/redis-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const deprecationMessage = [
'On the next versions having this settings will throw an exception',
].join(' ');

const upstashMessage = 'BullMQ: Upstash is not compatible with BullMQ.';

export class RedisConnection extends EventEmitter {
static minimumVersion = '5.0.0';
protected _client: RedisClient;
Expand Down Expand Up @@ -48,14 +50,16 @@ export class RedisConnection extends EventEmitter {
maxRetriesPerRequest: null,
enableReadyCheck: false,
};
this.checkUpstashHost(this.opts.host);
} else {
this._client = <RedisClient>opts;
let options = this._client.options;
let options = <IORedis.RedisOptions>this._client.options;
if ((<IORedis.ClusterOptions>options)?.redisOptions) {
options = (<IORedis.ClusterOptions>options).redisOptions;
}

this.checkOptions(deprecationMessage, options);
this.checkUpstashHost(options.host);
}

this.handleClientError = (err: Error): void => {
Expand All @@ -72,6 +76,12 @@ export class RedisConnection extends EventEmitter {
}
}

private checkUpstashHost(host: string) {
if (host.endsWith('upstash.io')) {
throw new Error(upstashMessage);
}
}

/**
* Waits for a redis client to be ready.
* @param redis - client
Expand Down
14 changes: 14 additions & 0 deletions tests/test_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ describe('connection', () => {
checkOptions(await queue.client);
});

describe('when host belongs to Upstash', async () => {
it('throws an error', async () => {
const opts = {
connection: {
host: 'https://upstash.io',
},
};

expect(() => new QueueBase(queueName, opts)).to.throw(
'BullMQ: Upstash is not compatible with BullMQ.',
);
});
});

it('should recover from a connection loss', async () => {
let processor;

Expand Down

0 comments on commit 5156d0a

Please sign in to comment.