bullmq 6.6.1 → 6.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/classes/queue-getters.js +12 -2
- package/dist/cjs/classes/redis-queue-backend.js +6 -4
- package/dist/cjs/commands/getCounts-1.lua +9 -2
- package/dist/cjs/postgres/postgres-queue-backend.js +13 -1
- package/dist/cjs/postgres/sql-scripts.js +1 -0
- package/dist/cjs/scripts/getCounts-1.js +9 -2
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/classes/queue-getters.d.ts +4 -1
- package/dist/esm/classes/queue-getters.js +12 -2
- package/dist/esm/classes/redis-queue-backend.d.ts +1 -1
- package/dist/esm/classes/redis-queue-backend.js +6 -4
- package/dist/esm/commands/getCounts-1.lua +9 -2
- package/dist/esm/interfaces/queue-backend.d.ts +5 -1
- package/dist/esm/postgres/postgres-queue-backend.d.ts +1 -1
- package/dist/esm/postgres/postgres-queue-backend.js +13 -1
- package/dist/esm/postgres/sql-scripts.js +1 -0
- package/dist/esm/scripts/getCounts-1.js +9 -2
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -220,9 +220,19 @@ class QueueGetters extends queue_base_1.QueueBase {
|
|
|
220
220
|
}
|
|
221
221
|
/**
|
|
222
222
|
* Returns the number of jobs in delayed status.
|
|
223
|
+
*
|
|
224
|
+
* @param timestamp - Optional Unix timestamp as a safe integer in milliseconds.
|
|
225
|
+
* When provided, only counts jobs scheduled strictly before this timestamp.
|
|
223
226
|
*/
|
|
224
|
-
getDelayedCount() {
|
|
225
|
-
|
|
227
|
+
async getDelayedCount(timestamp) {
|
|
228
|
+
if (timestamp === undefined) {
|
|
229
|
+
return this.getJobCountByTypes('delayed');
|
|
230
|
+
}
|
|
231
|
+
if (!Number.isSafeInteger(timestamp)) {
|
|
232
|
+
throw new Error('timestamp must be a safe integer in milliseconds');
|
|
233
|
+
}
|
|
234
|
+
const [count] = await this.backend.getCounts(['delayed'], timestamp);
|
|
235
|
+
return count;
|
|
226
236
|
}
|
|
227
237
|
/**
|
|
228
238
|
* Returns the number of jobs in active status.
|
|
@@ -934,18 +934,20 @@ class RedisQueueBackend extends node_events_1.EventEmitter {
|
|
|
934
934
|
const args = this.getJobsArgs(types, start, end, asc);
|
|
935
935
|
return await this.execCommand(client, 'getJobs', args);
|
|
936
936
|
}
|
|
937
|
-
getCountsArgs(types) {
|
|
937
|
+
getCountsArgs(types, delayedTimestamp) {
|
|
938
938
|
const queueKeys = this.queue.keys;
|
|
939
939
|
const transformedTypes = types.map(type => {
|
|
940
940
|
return type === 'waiting' ? 'wait' : type;
|
|
941
941
|
});
|
|
942
942
|
const keys = [queueKeys['']];
|
|
943
|
-
const args =
|
|
943
|
+
const args = delayedTimestamp === undefined
|
|
944
|
+
? transformedTypes
|
|
945
|
+
: [delayedTimestamp, ...transformedTypes];
|
|
944
946
|
return keys.concat(args);
|
|
945
947
|
}
|
|
946
|
-
async getCounts(types) {
|
|
948
|
+
async getCounts(types, delayedTimestamp) {
|
|
947
949
|
const client = await this.queue.client;
|
|
948
|
-
const args = this.getCountsArgs(types);
|
|
950
|
+
const args = this.getCountsArgs(types, delayedTimestamp);
|
|
949
951
|
return await this.execCommand(client, 'getCounts', args);
|
|
950
952
|
}
|
|
951
953
|
getCountsPerPriorityArgs(priorities) {
|
|
@@ -4,13 +4,16 @@
|
|
|
4
4
|
Input:
|
|
5
5
|
KEYS[1] 'prefix'
|
|
6
6
|
|
|
7
|
-
ARGV[1
|
|
7
|
+
ARGV[1] optional delayed timestamp cutoff (milliseconds)
|
|
8
|
+
ARGV[...] types (starts at 1 when no cutoff is provided)
|
|
8
9
|
]]
|
|
9
10
|
local rcall = redis.call;
|
|
10
11
|
local prefix = KEYS[1]
|
|
11
12
|
local results = {}
|
|
13
|
+
local delayedTimestamp = tonumber(ARGV[1])
|
|
14
|
+
local firstType = delayedTimestamp and 2 or 1
|
|
12
15
|
|
|
13
|
-
for i =
|
|
16
|
+
for i = firstType, #ARGV do
|
|
14
17
|
local stateKey = prefix .. ARGV[i]
|
|
15
18
|
if ARGV[i] == "wait" or ARGV[i] == "paused" then
|
|
16
19
|
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
|
@@ -28,6 +31,10 @@ for i = 1, #ARGV do
|
|
|
28
31
|
end
|
|
29
32
|
elseif ARGV[i] == "active" then
|
|
30
33
|
results[#results+1] = rcall("LLEN", stateKey)
|
|
34
|
+
elseif ARGV[i] == "delayed" and delayedTimestamp then
|
|
35
|
+
-- The low 12 score bits order jobs within a millisecond. Subtracting one
|
|
36
|
+
-- excludes every job scheduled at the cutoff timestamp or later.
|
|
37
|
+
results[#results+1] = rcall("ZCOUNT", stateKey, "-inf", delayedTimestamp * 0x1000 - 1)
|
|
31
38
|
else
|
|
32
39
|
results[#results+1] = rcall("ZCARD", stateKey)
|
|
33
40
|
end
|
|
@@ -1235,7 +1235,19 @@ class PostgresQueueBackend extends node_events_1.EventEmitter {
|
|
|
1235
1235
|
]);
|
|
1236
1236
|
return Number(rows[0].ttl);
|
|
1237
1237
|
}
|
|
1238
|
-
async getCounts(types) {
|
|
1238
|
+
async getCounts(types, delayedTimestamp) {
|
|
1239
|
+
if (delayedTimestamp !== undefined && types.includes('delayed')) {
|
|
1240
|
+
const otherTypes = types.filter(type => type !== 'delayed');
|
|
1241
|
+
const [{ rows }, otherCounts] = await Promise.all([
|
|
1242
|
+
this.run('get_delayed_count', [
|
|
1243
|
+
this.queueName,
|
|
1244
|
+
delayedTimestamp,
|
|
1245
|
+
]),
|
|
1246
|
+
otherTypes.length ? this.getCounts(otherTypes) : Promise.resolve([]),
|
|
1247
|
+
]);
|
|
1248
|
+
let index = 0;
|
|
1249
|
+
return types.map(type => type === 'delayed' ? Number(rows[0].count) : otherCounts[index++]);
|
|
1250
|
+
}
|
|
1239
1251
|
const { rows } = await this.run('get_counts', [
|
|
1240
1252
|
this.queueName,
|
|
1241
1253
|
]);
|
|
@@ -34,6 +34,7 @@ exports.SQL_COMMANDS = {
|
|
|
34
34
|
"get_counts.sql": "-- Job counts by state for a queue. Param: $1 queue.\n-- \"prioritized\" = waiting with priority > 0; \"waiting\" = waiting with priority 0.\nSELECT\n COUNT(*) FILTER (WHERE state = 'active') AS active,\n COUNT(*) FILTER (WHERE state = 'completed') AS completed,\n COUNT(*) FILTER (WHERE state = 'failed') AS failed,\n COUNT(*) FILTER (WHERE state = 'delayed') AS delayed,\n COUNT(*) FILTER (WHERE state = 'waiting' AND priority = 0) AS waiting,\n COUNT(*) FILTER (WHERE state = 'waiting' AND priority > 0) AS prioritized,\n COUNT(*) FILTER (WHERE state = 'waiting-children') AS \"waiting-children\",\n (SELECT value FROM meta WHERE queue = $1 AND field = 'paused') AS paused\nFROM job\nWHERE queue = $1;\n",
|
|
35
35
|
"get_counts_per_priority.sql": "-- Waiting-job counts per priority. Params: $1 queue, $2 priorities (bigint[]).\n-- Returns one row per requested priority, in the input array order, with the\n-- number of waiting jobs at that priority. Pausing is an O(1) meta flag that\n-- leaves jobs in the 'waiting' state, so the counts are identical whether or\n-- not the queue is paused (mirrors Redis, where pausing does not touch the\n-- wait/prioritized sets).\nSELECT COUNT(j.id) AS cnt\nFROM unnest($2::bigint[]) WITH ORDINALITY AS pr(priority, ord)\nLEFT JOIN job j\n ON j.queue = $1\n AND j.state = 'waiting'\n AND j.priority = pr.priority\nGROUP BY pr.ord\nORDER BY pr.ord;\n",
|
|
36
36
|
"get_deduplication_job_id.sql": "-- The current \"winner\" job id for a deduplication key, or none when absent or\n-- expired. Params: $1 queue, $2 dedup_id, $3 now (ms).\nSELECT job_id\nFROM dedup\nWHERE queue = $1\n AND dedup_id = $2\n AND (expire_at_ms IS NULL OR expire_at_ms > $3);\n",
|
|
37
|
+
"get_delayed_count.sql": "-- Delayed jobs scheduled strictly before $2 (Unix milliseconds). $1 is queue.\nSELECT COUNT(*) AS count\nFROM job\nWHERE queue = $1 AND state = 'delayed' AND process_at_ms < $2::bigint;\n",
|
|
37
38
|
"get_dependencies.sql": "-- All of a parent job's child dependencies with their status and stored value.\n-- Params: $1 parent_queue, $2 parent_id. Status maps to the public categories:\n-- processed → processed (value = return value), pending → unprocessed,\n-- ignored → ignored (value = reason), failed → failed.\nSELECT status::text AS status, child_key, value\nFROM job_dependency\nWHERE parent_queue = $1 AND parent_id = $2\nORDER BY child_id;\n",
|
|
38
39
|
"get_dependencies_page.sql": "-- One page of a parent's child dependencies in a single status category.\n-- Params: $1 parent_queue, $2 parent_id, $3 status, $4 offset, $5 count.\nSELECT child_key, value\nFROM job_dependency\nWHERE parent_queue = $1 AND parent_id = $2 AND status = $3::dep_status\nORDER BY child_id\nOFFSET $4 LIMIT $5;\n",
|
|
39
40
|
"get_dependency_counts.sql": "-- Child-dependency counts per status for a parent job.\n-- Params: $1 parent_queue, $2 parent_id. (\"unprocessed\" = pending children.)\nSELECT\n COUNT(*) FILTER (WHERE status = 'processed') AS processed,\n COUNT(*) FILTER (WHERE status = 'pending') AS unprocessed,\n COUNT(*) FILTER (WHERE status = 'ignored') AS ignored,\n COUNT(*) FILTER (WHERE status = 'failed') AS failed\nFROM job_dependency\nWHERE parent_queue = $1 AND parent_id = $2;\n",
|
|
@@ -5,12 +5,15 @@ const content = `--[[
|
|
|
5
5
|
Get counts per provided states
|
|
6
6
|
Input:
|
|
7
7
|
KEYS[1] 'prefix'
|
|
8
|
-
ARGV[1
|
|
8
|
+
ARGV[1] optional delayed timestamp cutoff (milliseconds)
|
|
9
|
+
ARGV[...] types (starts at 1 when no cutoff is provided)
|
|
9
10
|
]]
|
|
10
11
|
local rcall = redis.call;
|
|
11
12
|
local prefix = KEYS[1]
|
|
12
13
|
local results = {}
|
|
13
|
-
|
|
14
|
+
local delayedTimestamp = tonumber(ARGV[1])
|
|
15
|
+
local firstType = delayedTimestamp and 2 or 1
|
|
16
|
+
for i = firstType, #ARGV do
|
|
14
17
|
local stateKey = prefix .. ARGV[i]
|
|
15
18
|
if ARGV[i] == "wait" or ARGV[i] == "paused" then
|
|
16
19
|
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
|
@@ -28,6 +31,10 @@ for i = 1, #ARGV do
|
|
|
28
31
|
end
|
|
29
32
|
elseif ARGV[i] == "active" then
|
|
30
33
|
results[#results+1] = rcall("LLEN", stateKey)
|
|
34
|
+
elseif ARGV[i] == "delayed" and delayedTimestamp then
|
|
35
|
+
-- The low 12 score bits order jobs within a millisecond. Subtracting one
|
|
36
|
+
-- excludes every job scheduled at the cutoff timestamp or later.
|
|
37
|
+
results[#results+1] = rcall("ZCOUNT", stateKey, "-inf", delayedTimestamp * 0x1000 - 1)
|
|
31
38
|
else
|
|
32
39
|
results[#results+1] = rcall("ZCARD", stateKey)
|
|
33
40
|
end
|