Comparing version 3.16.0 to 3.16.1
@@ -383,3 +383,3 @@ "use strict"; | ||
const args = this.scripts.moveToDelayedArgs(this.id, Date.now() + delay, token); | ||
multi.moveToDelayed(args); | ||
this.scripts.execCommand(multi, 'moveToDelayed', args); | ||
command = 'delayed'; | ||
@@ -389,3 +389,3 @@ } | ||
// Retry immediately | ||
multi.retryJob(this.scripts.retryJobArgs(this.id, this.opts.lifo, token)); | ||
this.scripts.execCommand(multi, 'retryJob', this.scripts.retryJobArgs(this.id, this.opts.lifo, token)); | ||
command = 'retryJob'; | ||
@@ -400,3 +400,3 @@ } | ||
const args = this.scripts.moveToFailedArgs(this, message, this.opts.removeOnFail, token, fetchNext); | ||
multi.moveToFinished(args); | ||
this.scripts.execCommand(multi, 'moveToFinished', args); | ||
finishedOn = args[13]; | ||
@@ -740,3 +740,3 @@ command = 'failed'; | ||
const args = this.scripts.saveStacktraceArgs(this.id, JSON.stringify(this.stacktrace), err === null || err === void 0 ? void 0 : err.message); | ||
multi.saveStacktrace(args); | ||
this.scripts.execCommand(multi, 'saveStacktrace', args); | ||
} | ||
@@ -743,0 +743,0 @@ } |
@@ -102,8 +102,9 @@ "use strict"; | ||
} | ||
loadCommands(providedScripts) { | ||
loadCommands(version, providedScripts) { | ||
const finalScripts = providedScripts || scripts; | ||
for (const property in finalScripts) { | ||
// Only define the command if not already defined | ||
if (!this._client[finalScripts[property].name]) { | ||
this._client.defineCommand(finalScripts[property].name, { | ||
const commandName = `${finalScripts[property].name}:${version}`; | ||
if (!this._client[commandName]) { | ||
this._client.defineCommand(commandName, { | ||
numberOfKeys: finalScripts[property].keys, | ||
@@ -123,4 +124,5 @@ lua: finalScripts[property].content, | ||
this._client.on('ready', this.handleClientReady); | ||
const { version } = (0, utils_2.readPackageJson)(); | ||
await RedisConnection.waitUntilReady(this._client); | ||
this.loadCommands(); | ||
this.loadCommands(version); | ||
this.version = await this.getRedisVersion(); | ||
@@ -127,0 +129,0 @@ if (this.opts && this.opts.skipVersionCheck !== true && !this.closing) { |
@@ -20,2 +20,3 @@ /** | ||
const queueKeys = this.queue.keys; | ||
this.version = (0, utils_1.readPackageJson)().version; | ||
this.moveToFinishedKeys = [ | ||
@@ -36,2 +37,6 @@ queueKeys.wait, | ||
} | ||
execCommand(client, commandName, args) { | ||
const commandNameWithVersion = `${commandName}:${this.version}`; | ||
return client[commandNameWithVersion](args); | ||
} | ||
async isJobInList(listKey, jobId) { | ||
@@ -41,3 +46,3 @@ const client = await this.queue.client; | ||
if ((0, utils_1.isRedisVersionLowerThan)(this.queue.redisVersion, '6.0.6')) { | ||
result = await client.isJobInList([listKey, jobId]); | ||
result = await this.execCommand(client, 'isJobInList', [listKey, jobId]); | ||
} | ||
@@ -89,3 +94,3 @@ else { | ||
keys.push(pack(args), job.data, encodedOpts); | ||
const result = await client.addJob(keys); | ||
const result = await this.execCommand(client, 'addJob', keys); | ||
if (result < 0) { | ||
@@ -105,3 +110,3 @@ throw this.finishedErrors(result, parentOpts.parentKey, 'addJob'); | ||
keys.push(this.queue.keys.events); | ||
return client.pause(keys.concat([pause ? 'paused' : 'resumed'])); | ||
return this.execCommand(client, 'pause', keys.concat([pause ? 'paused' : 'resumed'])); | ||
} | ||
@@ -117,3 +122,3 @@ removeRepeatableArgs(repeatJobId, repeatJobKey) { | ||
const args = this.removeRepeatableArgs(repeatJobId, repeatJobKey); | ||
return client.removeRepeatable(args); | ||
return this.execCommand(client, 'removeRepeatable', args); | ||
} | ||
@@ -123,3 +128,3 @@ async remove(jobId) { | ||
const keys = [''].map(name => this.queue.toKey(name)); | ||
return client.removeJob(keys.concat([jobId])); | ||
return this.execCommand(client, 'removeJob', keys.concat([jobId])); | ||
} | ||
@@ -135,3 +140,3 @@ async extendLock(jobId, token, duration, client) { | ||
]; | ||
return client.extendLock(args); | ||
return this.execCommand(client, 'extendLock', args); | ||
} | ||
@@ -142,3 +147,3 @@ async updateData(job, data) { | ||
const dataJson = JSON.stringify(data); | ||
const result = await client.updateData(keys.concat([dataJson])); | ||
const result = await this.execCommand(client, 'updateData', keys.concat([dataJson])); | ||
if (result < 0) { | ||
@@ -152,3 +157,3 @@ throw this.finishedErrors(result, job.id, 'updateData'); | ||
const progressJson = JSON.stringify(progress); | ||
const result = await client.updateProgress(keys.concat([job.id, progressJson])); | ||
const result = await this.execCommand(client, 'updateProgress', keys.concat([job.id, progressJson])); | ||
if (result < 0) { | ||
@@ -206,3 +211,3 @@ throw this.finishedErrors(result, job.id, 'updateProgress'); | ||
const client = await this.queue.client; | ||
const result = await client.moveToFinished(args); | ||
const result = await this.execCommand(client, 'moveToFinished', args); | ||
if (result < 0) { | ||
@@ -249,3 +254,3 @@ throw this.finishedErrors(result, jobId, 'moveToFinished', 'active'); | ||
const args = this.drainArgs(delayed); | ||
return client.drain(args); | ||
return this.execCommand(client, 'drain', args); | ||
} | ||
@@ -264,3 +269,3 @@ getRangesArgs(types, start, end, asc) { | ||
const args = this.getRangesArgs(types, start, end, asc); | ||
return client.getRanges(args); | ||
return this.execCommand(client, 'getRanges', args); | ||
} | ||
@@ -279,3 +284,3 @@ getCountsArgs(types) { | ||
const args = this.getCountsArgs(types); | ||
return client.getCounts(args); | ||
return this.execCommand(client, 'getCounts', args); | ||
} | ||
@@ -295,3 +300,3 @@ moveToCompletedArgs(job, returnvalue, removeOnComplete, token, fetchNext = false) { | ||
}); | ||
return client.isFinished(keys.concat([jobId, returnValue ? '1' : ''])); | ||
return this.execCommand(client, 'isFinished', keys.concat([jobId, returnValue ? '1' : ''])); | ||
} | ||
@@ -312,5 +317,5 @@ async getState(jobId) { | ||
if ((0, utils_1.isRedisVersionLowerThan)(this.queue.redisVersion, '6.0.6')) { | ||
return client.getState(keys.concat([jobId])); | ||
return this.execCommand(client, 'getState', keys.concat([jobId])); | ||
} | ||
return client.getStateV2(keys.concat([jobId])); | ||
return this.execCommand(client, 'getStateV2', keys.concat([jobId])); | ||
} | ||
@@ -320,3 +325,3 @@ async changeDelay(jobId, delay) { | ||
const args = this.changeDelayArgs(jobId, delay); | ||
const result = await client.changeDelay(args); | ||
const result = await this.execCommand(client, 'changeDelay', args); | ||
if (result < 0) { | ||
@@ -347,3 +352,3 @@ throw this.finishedErrors(result, jobId, 'changeDelay', 'delayed'); | ||
const args = this.changePriorityArgs(jobId, priority, lifo); | ||
const result = await client.changePriority(args); | ||
const result = await this.execCommand(client, 'changePriority', args); | ||
if (result < 0) { | ||
@@ -422,3 +427,3 @@ throw this.finishedErrors(result, jobId, 'changePriority'); | ||
const args = this.moveToDelayedArgs(jobId, timestamp, token); | ||
const result = await client.moveToDelayed(args); | ||
const result = await this.execCommand(client, 'moveToDelayed', args); | ||
if (result < 0) { | ||
@@ -442,3 +447,3 @@ throw this.finishedErrors(result, jobId, 'moveToDelayed', 'active'); | ||
const args = this.moveToWaitingChildrenArgs(jobId, token, opts); | ||
const result = await client.moveToWaitingChildren(args); | ||
const result = await this.execCommand(client, 'moveToWaitingChildren', args); | ||
switch (result) { | ||
@@ -460,3 +465,3 @@ case 0: | ||
const client = await this.queue.client; | ||
return client.cleanJobsInSet([ | ||
return this.execCommand(client, 'cleanJobsInSet', [ | ||
this.queue.toKey(set), | ||
@@ -505,3 +510,3 @@ this.queue.toKey('events'), | ||
const args = this.retryJobsArgs(state, count, timestamp); | ||
return client.retryJobs(args); | ||
return this.execCommand(client, 'retryJobs', args); | ||
} | ||
@@ -537,3 +542,3 @@ /** | ||
]; | ||
const result = await client.reprocessJob(keys.concat(args)); | ||
const result = await this.execCommand(client, 'reprocessJob', keys.concat(args)); | ||
switch (result) { | ||
@@ -571,3 +576,3 @@ case 1: | ||
]; | ||
const result = await client.moveToActive(keys.concat(args)); | ||
const result = await this.execCommand(client, 'moveToActive', keys.concat(args)); | ||
return raw2NextJobData(result); | ||
@@ -586,3 +591,3 @@ } | ||
const args = [this.queue.toKey(''), jobId]; | ||
return client.promote(keys.concat(args)); | ||
return this.execCommand(client, 'promote', keys.concat(args)); | ||
} | ||
@@ -617,3 +622,3 @@ /** | ||
]; | ||
return client.moveStalledJobsToWait(keys.concat(args)); | ||
return this.execCommand(client, 'moveStalledJobsToWait', keys.concat(args)); | ||
} | ||
@@ -644,3 +649,3 @@ /** | ||
const args = [jobId, token, this.queue.toKey(jobId)]; | ||
const pttl = await client.moveJobFromActiveToWait(keys.concat(args)); | ||
const pttl = await this.execCommand(client, 'moveJobFromActiveToWait', keys.concat(args)); | ||
return pttl < 0 ? 0 : pttl; | ||
@@ -655,3 +660,3 @@ } | ||
const args = [opts.count, opts.force ? 'force' : null]; | ||
const result = await client.obliterate(keys.concat(args)); | ||
const result = await this.execCommand(client, 'obliterate', keys.concat(args)); | ||
if (result < 0) { | ||
@@ -658,0 +663,0 @@ switch (result) { |
@@ -380,3 +380,3 @@ import { __rest } from "tslib"; | ||
const args = this.scripts.moveToDelayedArgs(this.id, Date.now() + delay, token); | ||
multi.moveToDelayed(args); | ||
this.scripts.execCommand(multi, 'moveToDelayed', args); | ||
command = 'delayed'; | ||
@@ -386,3 +386,3 @@ } | ||
// Retry immediately | ||
multi.retryJob(this.scripts.retryJobArgs(this.id, this.opts.lifo, token)); | ||
this.scripts.execCommand(multi, 'retryJob', this.scripts.retryJobArgs(this.id, this.opts.lifo, token)); | ||
command = 'retryJob'; | ||
@@ -397,3 +397,3 @@ } | ||
const args = this.scripts.moveToFailedArgs(this, message, this.opts.removeOnFail, token, fetchNext); | ||
multi.moveToFinished(args); | ||
this.scripts.execCommand(multi, 'moveToFinished', args); | ||
finishedOn = args[13]; | ||
@@ -737,3 +737,3 @@ command = 'failed'; | ||
const args = this.scripts.saveStacktraceArgs(this.id, JSON.stringify(this.stacktrace), err === null || err === void 0 ? void 0 : err.message); | ||
multi.saveStacktrace(args); | ||
this.scripts.execCommand(multi, 'saveStacktrace', args); | ||
} | ||
@@ -740,0 +740,0 @@ } |
@@ -30,3 +30,3 @@ /// <reference types="node" /> | ||
get client(): Promise<RedisClient>; | ||
protected loadCommands(providedScripts?: Record<string, RawCommand>): void; | ||
protected loadCommands(version?: string, providedScripts?: Record<string, RawCommand>): void; | ||
private init; | ||
@@ -33,0 +33,0 @@ disconnect(): Promise<void>; |
@@ -6,3 +6,3 @@ import { EventEmitter } from 'events'; | ||
import { CONNECTION_CLOSED_ERROR_MSG } from 'ioredis/built/utils'; | ||
import { isNotConnectionError, isRedisCluster, isRedisInstance, isRedisVersionLowerThan, } from '../utils'; | ||
import { isNotConnectionError, isRedisCluster, isRedisInstance, isRedisVersionLowerThan, readPackageJson, } from '../utils'; | ||
import * as scripts from '../scripts'; | ||
@@ -100,8 +100,9 @@ const overrideMessage = [ | ||
} | ||
loadCommands(providedScripts) { | ||
loadCommands(version, providedScripts) { | ||
const finalScripts = providedScripts || scripts; | ||
for (const property in finalScripts) { | ||
// Only define the command if not already defined | ||
if (!this._client[finalScripts[property].name]) { | ||
this._client.defineCommand(finalScripts[property].name, { | ||
const commandName = `${finalScripts[property].name}:${version}`; | ||
if (!this._client[commandName]) { | ||
this._client.defineCommand(commandName, { | ||
numberOfKeys: finalScripts[property].keys, | ||
@@ -121,4 +122,5 @@ lua: finalScripts[property].content, | ||
this._client.on('ready', this.handleClientReady); | ||
const { version } = readPackageJson(); | ||
await RedisConnection.waitUntilReady(this._client); | ||
this.loadCommands(); | ||
this.loadCommands(version); | ||
this.version = await this.getRedisVersion(); | ||
@@ -125,0 +127,0 @@ if (this.opts && this.opts.skipVersionCheck !== true && !this.closing) { |
@@ -11,4 +11,6 @@ /** | ||
protected queue: MinimalQueue; | ||
protected version: string; | ||
moveToFinishedKeys: (string | undefined)[]; | ||
constructor(queue: MinimalQueue); | ||
execCommand(client: RedisClient | ChainableCommander, commandName: string, args: any[]): any; | ||
isJobInList(listKey: string, jobId: string): Promise<boolean>; | ||
@@ -15,0 +17,0 @@ addJob(client: RedisClient, job: JobJson, opts: RedisJobOptions, jobId: string, parentOpts?: ParentOpts): Promise<string>; |
@@ -13,3 +13,3 @@ /** | ||
import { ErrorCode } from '../enums'; | ||
import { array2obj, getParentKey, isRedisVersionLowerThan } from '../utils'; | ||
import { array2obj, getParentKey, isRedisVersionLowerThan, readPackageJson, } from '../utils'; | ||
export class Scripts { | ||
@@ -19,2 +19,3 @@ constructor(queue) { | ||
const queueKeys = this.queue.keys; | ||
this.version = readPackageJson().version; | ||
this.moveToFinishedKeys = [ | ||
@@ -35,2 +36,6 @@ queueKeys.wait, | ||
} | ||
execCommand(client, commandName, args) { | ||
const commandNameWithVersion = `${commandName}:${this.version}`; | ||
return client[commandNameWithVersion](args); | ||
} | ||
async isJobInList(listKey, jobId) { | ||
@@ -40,3 +45,3 @@ const client = await this.queue.client; | ||
if (isRedisVersionLowerThan(this.queue.redisVersion, '6.0.6')) { | ||
result = await client.isJobInList([listKey, jobId]); | ||
result = await this.execCommand(client, 'isJobInList', [listKey, jobId]); | ||
} | ||
@@ -88,3 +93,3 @@ else { | ||
keys.push(pack(args), job.data, encodedOpts); | ||
const result = await client.addJob(keys); | ||
const result = await this.execCommand(client, 'addJob', keys); | ||
if (result < 0) { | ||
@@ -104,3 +109,3 @@ throw this.finishedErrors(result, parentOpts.parentKey, 'addJob'); | ||
keys.push(this.queue.keys.events); | ||
return client.pause(keys.concat([pause ? 'paused' : 'resumed'])); | ||
return this.execCommand(client, 'pause', keys.concat([pause ? 'paused' : 'resumed'])); | ||
} | ||
@@ -116,3 +121,3 @@ removeRepeatableArgs(repeatJobId, repeatJobKey) { | ||
const args = this.removeRepeatableArgs(repeatJobId, repeatJobKey); | ||
return client.removeRepeatable(args); | ||
return this.execCommand(client, 'removeRepeatable', args); | ||
} | ||
@@ -122,3 +127,3 @@ async remove(jobId) { | ||
const keys = [''].map(name => this.queue.toKey(name)); | ||
return client.removeJob(keys.concat([jobId])); | ||
return this.execCommand(client, 'removeJob', keys.concat([jobId])); | ||
} | ||
@@ -134,3 +139,3 @@ async extendLock(jobId, token, duration, client) { | ||
]; | ||
return client.extendLock(args); | ||
return this.execCommand(client, 'extendLock', args); | ||
} | ||
@@ -141,3 +146,3 @@ async updateData(job, data) { | ||
const dataJson = JSON.stringify(data); | ||
const result = await client.updateData(keys.concat([dataJson])); | ||
const result = await this.execCommand(client, 'updateData', keys.concat([dataJson])); | ||
if (result < 0) { | ||
@@ -151,3 +156,3 @@ throw this.finishedErrors(result, job.id, 'updateData'); | ||
const progressJson = JSON.stringify(progress); | ||
const result = await client.updateProgress(keys.concat([job.id, progressJson])); | ||
const result = await this.execCommand(client, 'updateProgress', keys.concat([job.id, progressJson])); | ||
if (result < 0) { | ||
@@ -205,3 +210,3 @@ throw this.finishedErrors(result, job.id, 'updateProgress'); | ||
const client = await this.queue.client; | ||
const result = await client.moveToFinished(args); | ||
const result = await this.execCommand(client, 'moveToFinished', args); | ||
if (result < 0) { | ||
@@ -248,3 +253,3 @@ throw this.finishedErrors(result, jobId, 'moveToFinished', 'active'); | ||
const args = this.drainArgs(delayed); | ||
return client.drain(args); | ||
return this.execCommand(client, 'drain', args); | ||
} | ||
@@ -263,3 +268,3 @@ getRangesArgs(types, start, end, asc) { | ||
const args = this.getRangesArgs(types, start, end, asc); | ||
return client.getRanges(args); | ||
return this.execCommand(client, 'getRanges', args); | ||
} | ||
@@ -278,3 +283,3 @@ getCountsArgs(types) { | ||
const args = this.getCountsArgs(types); | ||
return client.getCounts(args); | ||
return this.execCommand(client, 'getCounts', args); | ||
} | ||
@@ -294,3 +299,3 @@ moveToCompletedArgs(job, returnvalue, removeOnComplete, token, fetchNext = false) { | ||
}); | ||
return client.isFinished(keys.concat([jobId, returnValue ? '1' : ''])); | ||
return this.execCommand(client, 'isFinished', keys.concat([jobId, returnValue ? '1' : ''])); | ||
} | ||
@@ -311,5 +316,5 @@ async getState(jobId) { | ||
if (isRedisVersionLowerThan(this.queue.redisVersion, '6.0.6')) { | ||
return client.getState(keys.concat([jobId])); | ||
return this.execCommand(client, 'getState', keys.concat([jobId])); | ||
} | ||
return client.getStateV2(keys.concat([jobId])); | ||
return this.execCommand(client, 'getStateV2', keys.concat([jobId])); | ||
} | ||
@@ -319,3 +324,3 @@ async changeDelay(jobId, delay) { | ||
const args = this.changeDelayArgs(jobId, delay); | ||
const result = await client.changeDelay(args); | ||
const result = await this.execCommand(client, 'changeDelay', args); | ||
if (result < 0) { | ||
@@ -346,3 +351,3 @@ throw this.finishedErrors(result, jobId, 'changeDelay', 'delayed'); | ||
const args = this.changePriorityArgs(jobId, priority, lifo); | ||
const result = await client.changePriority(args); | ||
const result = await this.execCommand(client, 'changePriority', args); | ||
if (result < 0) { | ||
@@ -421,3 +426,3 @@ throw this.finishedErrors(result, jobId, 'changePriority'); | ||
const args = this.moveToDelayedArgs(jobId, timestamp, token); | ||
const result = await client.moveToDelayed(args); | ||
const result = await this.execCommand(client, 'moveToDelayed', args); | ||
if (result < 0) { | ||
@@ -441,3 +446,3 @@ throw this.finishedErrors(result, jobId, 'moveToDelayed', 'active'); | ||
const args = this.moveToWaitingChildrenArgs(jobId, token, opts); | ||
const result = await client.moveToWaitingChildren(args); | ||
const result = await this.execCommand(client, 'moveToWaitingChildren', args); | ||
switch (result) { | ||
@@ -459,3 +464,3 @@ case 0: | ||
const client = await this.queue.client; | ||
return client.cleanJobsInSet([ | ||
return this.execCommand(client, 'cleanJobsInSet', [ | ||
this.queue.toKey(set), | ||
@@ -504,3 +509,3 @@ this.queue.toKey('events'), | ||
const args = this.retryJobsArgs(state, count, timestamp); | ||
return client.retryJobs(args); | ||
return this.execCommand(client, 'retryJobs', args); | ||
} | ||
@@ -536,3 +541,3 @@ /** | ||
]; | ||
const result = await client.reprocessJob(keys.concat(args)); | ||
const result = await this.execCommand(client, 'reprocessJob', keys.concat(args)); | ||
switch (result) { | ||
@@ -570,3 +575,3 @@ case 1: | ||
]; | ||
const result = await client.moveToActive(keys.concat(args)); | ||
const result = await this.execCommand(client, 'moveToActive', keys.concat(args)); | ||
return raw2NextJobData(result); | ||
@@ -585,3 +590,3 @@ } | ||
const args = [this.queue.toKey(''), jobId]; | ||
return client.promote(keys.concat(args)); | ||
return this.execCommand(client, 'promote', keys.concat(args)); | ||
} | ||
@@ -616,3 +621,3 @@ /** | ||
]; | ||
return client.moveStalledJobsToWait(keys.concat(args)); | ||
return this.execCommand(client, 'moveStalledJobsToWait', keys.concat(args)); | ||
} | ||
@@ -643,3 +648,3 @@ /** | ||
const args = [jobId, token, this.queue.toKey(jobId)]; | ||
const pttl = await client.moveJobFromActiveToWait(keys.concat(args)); | ||
const pttl = await this.execCommand(client, 'moveJobFromActiveToWait', keys.concat(args)); | ||
return pttl < 0 ? 0 : pttl; | ||
@@ -654,3 +659,3 @@ } | ||
const args = [opts.count, opts.force ? 'force' : null]; | ||
const result = await client.obliterate(keys.concat(args)); | ||
const result = await this.execCommand(client, 'obliterate', keys.concat(args)); | ||
if (result < 0) { | ||
@@ -657,0 +662,0 @@ switch (result) { |
{ | ||
"name": "bullmq", | ||
"version": "3.16.0", | ||
"version": "3.16.1", | ||
"description": "Queue for messages and jobs based on Redis", | ||
@@ -5,0 +5,0 @@ "homepage": "https://bullmq.io/", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1265615
19716