Skip to content

Commit

Permalink
feat(queue): add option to skip wait until connection ready
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Jan 28, 2025
1 parent 5dd9d23 commit e728299
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/classes/queue-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class QueueBase extends EventEmitter implements MinimalQueue {
shared: isRedisInstance(opts.connection),
blocking: hasBlockingConnection,
skipVersionCheck: opts.skipVersionCheck,
skipWaitingForReady: opts.skipWaitingForReady,
});

this.connection.on('error', (error: Error) => this.emit('error', error));
Expand Down
6 changes: 5 additions & 1 deletion src/classes/redis-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class RedisConnection extends EventEmitter {
shared?: boolean;
blocking?: boolean;
skipVersionCheck?: boolean;
skipWaitingForReady?: boolean;
},
) {
super();
Expand All @@ -73,6 +74,7 @@ export class RedisConnection extends EventEmitter {
shared: false,
blocking: true,
skipVersionCheck: false,
skipWaitingForReady: false,
...extraOptions,
};

Expand Down Expand Up @@ -241,7 +243,9 @@ export class RedisConnection extends EventEmitter {

this._client.on('ready', this.handleClientReady);

await RedisConnection.waitUntilReady(this._client);
if (!this.extraOptions.skipWaitingForReady) {
await RedisConnection.waitUntilReady(this._client);
}

this.loadCommands(this.packageVersion);

Expand Down
15 changes: 10 additions & 5 deletions src/interfaces/queue-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ export interface QueueBaseOptions {
* Telemetry client
*/
telemetry?: Telemetry;

/**
* Skip waiting for connection ready.
*
* In some instances if you want the queue to fail fast if the connection is
* not ready you can set this to true. This could be useful for testing and when
* adding jobs via HTTP endpoints for example.
*
*/
skipWaitingForReady?: boolean;
}

/**
Expand Down Expand Up @@ -75,11 +85,6 @@ export interface QueueOptions extends QueueBaseOptions {
* Advanced options for the repeatable jobs.
*/
settings?: AdvancedRepeatOptions;

/**
* Telemetry client
*/
telemetry?: Telemetry;
}

/**
Expand Down

0 comments on commit e728299

Please sign in to comment.