bullmq 6.3.11 → 6.3.13

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.
Files changed (204) hide show
  1. package/dist/cjs/classes/queue-getters.js +3 -1
  2. package/dist/cjs/classes/queue.js +2 -1
  3. package/dist/cjs/classes/redis-connection.js +1 -1
  4. package/dist/cjs/classes/redis-queue-backend.js +1 -1
  5. package/dist/cjs/commands/includes/moveChildBackToParentDependencies.lua +20 -0
  6. package/dist/cjs/commands/moveJobsToWait-8.lua +3 -0
  7. package/dist/cjs/commands/reprocessJob-7.lua +2 -14
  8. package/dist/cjs/postgres/sql-loader.js +27 -41
  9. package/dist/cjs/postgres/sql-scripts.js +110 -0
  10. package/dist/cjs/scripts/moveJobsToWait-8.js +21 -0
  11. package/dist/cjs/scripts/reprocessJob-7.js +20 -13
  12. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  13. package/dist/cjs/version.js +1 -1
  14. package/dist/esm/classes/queue-getters.d.ts +3 -1
  15. package/dist/esm/classes/queue-getters.js +3 -1
  16. package/dist/esm/classes/queue.d.ts +2 -1
  17. package/dist/esm/classes/queue.js +2 -1
  18. package/dist/esm/classes/redis-connection.d.ts +1 -1
  19. package/dist/esm/classes/redis-connection.js +1 -1
  20. package/dist/esm/classes/redis-queue-backend.d.ts +1 -1
  21. package/dist/esm/classes/redis-queue-backend.js +1 -1
  22. package/dist/esm/commands/includes/moveChildBackToParentDependencies.lua +20 -0
  23. package/dist/esm/commands/moveJobsToWait-8.lua +3 -0
  24. package/dist/esm/commands/reprocessJob-7.lua +2 -14
  25. package/dist/esm/postgres/sql-loader.d.ts +6 -1
  26. package/dist/esm/postgres/sql-loader.js +27 -41
  27. package/dist/esm/postgres/sql-scripts.d.ts +10 -0
  28. package/dist/esm/postgres/sql-scripts.js +107 -0
  29. package/dist/esm/scripts/moveJobsToWait-8.js +21 -0
  30. package/dist/esm/scripts/reprocessJob-7.js +20 -13
  31. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  32. package/dist/esm/version.d.ts +1 -1
  33. package/dist/esm/version.js +1 -1
  34. package/package.json +10 -9
  35. package/dist/cjs/postgres/commands/add_flow.sql +0 -3
  36. package/dist/cjs/postgres/commands/add_job.sql +0 -5
  37. package/dist/cjs/postgres/commands/add_job_scheduler.sql +0 -6
  38. package/dist/cjs/postgres/commands/add_jobs_bulk.sql +0 -3
  39. package/dist/cjs/postgres/commands/add_log.sql +0 -14
  40. package/dist/cjs/postgres/commands/change_delay.sql +0 -3
  41. package/dist/cjs/postgres/commands/change_priority.sql +0 -3
  42. package/dist/cjs/postgres/commands/clean.sql +0 -3
  43. package/dist/cjs/postgres/commands/clear_logs.sql +0 -9
  44. package/dist/cjs/postgres/commands/collect_metrics.sql +0 -4
  45. package/dist/cjs/postgres/commands/delete_deduplication_key.sql +0 -6
  46. package/dist/cjs/postgres/commands/drain.sql +0 -2
  47. package/dist/cjs/postgres/commands/extend_lock.sql +0 -3
  48. package/dist/cjs/postgres/commands/extend_locks.sql +0 -25
  49. package/dist/cjs/postgres/commands/get_client_list.sql +0 -11
  50. package/dist/cjs/postgres/commands/get_counts.sql +0 -13
  51. package/dist/cjs/postgres/commands/get_counts_per_priority.sql +0 -14
  52. package/dist/cjs/postgres/commands/get_deduplication_job_id.sql +0 -7
  53. package/dist/cjs/postgres/commands/get_dependencies.sql +0 -8
  54. package/dist/cjs/postgres/commands/get_dependencies_page.sql +0 -7
  55. package/dist/cjs/postgres/commands/get_dependency_counts.sql +0 -9
  56. package/dist/cjs/postgres/commands/get_ignored_children_failures.sql +0 -7
  57. package/dist/cjs/postgres/commands/get_job_data.sql +0 -2
  58. package/dist/cjs/postgres/commands/get_job_logs_asc.sql +0 -6
  59. package/dist/cjs/postgres/commands/get_job_logs_count.sql +0 -2
  60. package/dist/cjs/postgres/commands/get_job_logs_desc.sql +0 -6
  61. package/dist/cjs/postgres/commands/get_job_scheduler.sql +0 -6
  62. package/dist/cjs/postgres/commands/get_job_schedulers_count.sql +0 -2
  63. package/dist/cjs/postgres/commands/get_job_schedulers_range.sql +0 -10
  64. package/dist/cjs/postgres/commands/get_metrics.sql +0 -14
  65. package/dist/cjs/postgres/commands/get_processed_children_values.sql +0 -8
  66. package/dist/cjs/postgres/commands/get_queue_meta.sql +0 -2
  67. package/dist/cjs/postgres/commands/get_queue_meta_field.sql +0 -2
  68. package/dist/cjs/postgres/commands/get_queue_meta_fields.sql +0 -3
  69. package/dist/cjs/postgres/commands/get_range.sql +0 -3
  70. package/dist/cjs/postgres/commands/get_rate_limit_ttl.sql +0 -3
  71. package/dist/cjs/postgres/commands/get_state.sql +0 -2
  72. package/dist/cjs/postgres/commands/has_queue_meta_field.sql +0 -4
  73. package/dist/cjs/postgres/commands/has_waiting_job.sql +0 -11
  74. package/dist/cjs/postgres/commands/is_finished.sql +0 -4
  75. package/dist/cjs/postgres/commands/is_job_in_state.sql +0 -6
  76. package/dist/cjs/postgres/commands/is_job_in_wait.sql +0 -15
  77. package/dist/cjs/postgres/commands/is_job_prioritized.sql +0 -6
  78. package/dist/cjs/postgres/commands/is_job_scheduler.sql +0 -4
  79. package/dist/cjs/postgres/commands/is_maxed.sql +0 -10
  80. package/dist/cjs/postgres/commands/listen_events.sql +0 -3
  81. package/dist/cjs/postgres/commands/listen_jobs.sql +0 -4
  82. package/dist/cjs/postgres/commands/move_active_to_wait.sql +0 -4
  83. package/dist/cjs/postgres/commands/move_stalled_jobs_to_wait.sql +0 -4
  84. package/dist/cjs/postgres/commands/move_to_active.sql +0 -4
  85. package/dist/cjs/postgres/commands/move_to_completed.sql +0 -4
  86. package/dist/cjs/postgres/commands/move_to_completed_fetch.sql +0 -9
  87. package/dist/cjs/postgres/commands/move_to_delayed.sql +0 -4
  88. package/dist/cjs/postgres/commands/move_to_failed.sql +0 -4
  89. package/dist/cjs/postgres/commands/move_to_failed_fetch.sql +0 -9
  90. package/dist/cjs/postgres/commands/move_to_waiting_children.sql +0 -3
  91. package/dist/cjs/postgres/commands/next_delay.sql +0 -2
  92. package/dist/cjs/postgres/commands/next_signal.sql +0 -3
  93. package/dist/cjs/postgres/commands/obliterate.sql +0 -4
  94. package/dist/cjs/postgres/commands/paginate_dependencies.sql +0 -19
  95. package/dist/cjs/postgres/commands/pause.sql +0 -2
  96. package/dist/cjs/postgres/commands/promote.sql +0 -3
  97. package/dist/cjs/postgres/commands/promote_jobs.sql +0 -3
  98. package/dist/cjs/postgres/commands/publish_event.sql +0 -3
  99. package/dist/cjs/postgres/commands/read_events.sql +0 -6
  100. package/dist/cjs/postgres/commands/read_events_max.sql +0 -3
  101. package/dist/cjs/postgres/commands/remove.sql +0 -3
  102. package/dist/cjs/postgres/commands/remove_child_dependency.sql +0 -4
  103. package/dist/cjs/postgres/commands/remove_deduplication_key.sql +0 -9
  104. package/dist/cjs/postgres/commands/remove_job_scheduler.sql +0 -3
  105. package/dist/cjs/postgres/commands/remove_queue_meta_fields.sql +0 -2
  106. package/dist/cjs/postgres/commands/remove_rate_limit.sql +0 -6
  107. package/dist/cjs/postgres/commands/remove_unprocessed_children.sql +0 -3
  108. package/dist/cjs/postgres/commands/reprocess_job.sql +0 -4
  109. package/dist/cjs/postgres/commands/retry_job.sql +0 -3
  110. package/dist/cjs/postgres/commands/retry_jobs.sql +0 -3
  111. package/dist/cjs/postgres/commands/set_queue_meta.sql +0 -4
  112. package/dist/cjs/postgres/commands/set_rate_limit.sql +0 -3
  113. package/dist/cjs/postgres/commands/trim_logs.sql +0 -3
  114. package/dist/cjs/postgres/commands/update_data.sql +0 -3
  115. package/dist/cjs/postgres/commands/update_job_scheduler.sql +0 -5
  116. package/dist/cjs/postgres/commands/update_progress.sql +0 -3
  117. package/dist/cjs/postgres/migrations/0001_schema.sql +0 -348
  118. package/dist/cjs/postgres/migrations/0002_functions.sql +0 -3473
  119. package/dist/cjs/postgres/migrations/0003_dedup_stale_key.sql +0 -147
  120. package/dist/esm/postgres/commands/add_flow.sql +0 -3
  121. package/dist/esm/postgres/commands/add_job.sql +0 -5
  122. package/dist/esm/postgres/commands/add_job_scheduler.sql +0 -6
  123. package/dist/esm/postgres/commands/add_jobs_bulk.sql +0 -3
  124. package/dist/esm/postgres/commands/add_log.sql +0 -14
  125. package/dist/esm/postgres/commands/change_delay.sql +0 -3
  126. package/dist/esm/postgres/commands/change_priority.sql +0 -3
  127. package/dist/esm/postgres/commands/clean.sql +0 -3
  128. package/dist/esm/postgres/commands/clear_logs.sql +0 -9
  129. package/dist/esm/postgres/commands/collect_metrics.sql +0 -4
  130. package/dist/esm/postgres/commands/delete_deduplication_key.sql +0 -6
  131. package/dist/esm/postgres/commands/drain.sql +0 -2
  132. package/dist/esm/postgres/commands/extend_lock.sql +0 -3
  133. package/dist/esm/postgres/commands/extend_locks.sql +0 -25
  134. package/dist/esm/postgres/commands/get_client_list.sql +0 -11
  135. package/dist/esm/postgres/commands/get_counts.sql +0 -13
  136. package/dist/esm/postgres/commands/get_counts_per_priority.sql +0 -14
  137. package/dist/esm/postgres/commands/get_deduplication_job_id.sql +0 -7
  138. package/dist/esm/postgres/commands/get_dependencies.sql +0 -8
  139. package/dist/esm/postgres/commands/get_dependencies_page.sql +0 -7
  140. package/dist/esm/postgres/commands/get_dependency_counts.sql +0 -9
  141. package/dist/esm/postgres/commands/get_ignored_children_failures.sql +0 -7
  142. package/dist/esm/postgres/commands/get_job_data.sql +0 -2
  143. package/dist/esm/postgres/commands/get_job_logs_asc.sql +0 -6
  144. package/dist/esm/postgres/commands/get_job_logs_count.sql +0 -2
  145. package/dist/esm/postgres/commands/get_job_logs_desc.sql +0 -6
  146. package/dist/esm/postgres/commands/get_job_scheduler.sql +0 -6
  147. package/dist/esm/postgres/commands/get_job_schedulers_count.sql +0 -2
  148. package/dist/esm/postgres/commands/get_job_schedulers_range.sql +0 -10
  149. package/dist/esm/postgres/commands/get_metrics.sql +0 -14
  150. package/dist/esm/postgres/commands/get_processed_children_values.sql +0 -8
  151. package/dist/esm/postgres/commands/get_queue_meta.sql +0 -2
  152. package/dist/esm/postgres/commands/get_queue_meta_field.sql +0 -2
  153. package/dist/esm/postgres/commands/get_queue_meta_fields.sql +0 -3
  154. package/dist/esm/postgres/commands/get_range.sql +0 -3
  155. package/dist/esm/postgres/commands/get_rate_limit_ttl.sql +0 -3
  156. package/dist/esm/postgres/commands/get_state.sql +0 -2
  157. package/dist/esm/postgres/commands/has_queue_meta_field.sql +0 -4
  158. package/dist/esm/postgres/commands/has_waiting_job.sql +0 -11
  159. package/dist/esm/postgres/commands/is_finished.sql +0 -4
  160. package/dist/esm/postgres/commands/is_job_in_state.sql +0 -6
  161. package/dist/esm/postgres/commands/is_job_in_wait.sql +0 -15
  162. package/dist/esm/postgres/commands/is_job_prioritized.sql +0 -6
  163. package/dist/esm/postgres/commands/is_job_scheduler.sql +0 -4
  164. package/dist/esm/postgres/commands/is_maxed.sql +0 -10
  165. package/dist/esm/postgres/commands/listen_events.sql +0 -3
  166. package/dist/esm/postgres/commands/listen_jobs.sql +0 -4
  167. package/dist/esm/postgres/commands/move_active_to_wait.sql +0 -4
  168. package/dist/esm/postgres/commands/move_stalled_jobs_to_wait.sql +0 -4
  169. package/dist/esm/postgres/commands/move_to_active.sql +0 -4
  170. package/dist/esm/postgres/commands/move_to_completed.sql +0 -4
  171. package/dist/esm/postgres/commands/move_to_completed_fetch.sql +0 -9
  172. package/dist/esm/postgres/commands/move_to_delayed.sql +0 -4
  173. package/dist/esm/postgres/commands/move_to_failed.sql +0 -4
  174. package/dist/esm/postgres/commands/move_to_failed_fetch.sql +0 -9
  175. package/dist/esm/postgres/commands/move_to_waiting_children.sql +0 -3
  176. package/dist/esm/postgres/commands/next_delay.sql +0 -2
  177. package/dist/esm/postgres/commands/next_signal.sql +0 -3
  178. package/dist/esm/postgres/commands/obliterate.sql +0 -4
  179. package/dist/esm/postgres/commands/paginate_dependencies.sql +0 -19
  180. package/dist/esm/postgres/commands/pause.sql +0 -2
  181. package/dist/esm/postgres/commands/promote.sql +0 -3
  182. package/dist/esm/postgres/commands/promote_jobs.sql +0 -3
  183. package/dist/esm/postgres/commands/publish_event.sql +0 -3
  184. package/dist/esm/postgres/commands/read_events.sql +0 -6
  185. package/dist/esm/postgres/commands/read_events_max.sql +0 -3
  186. package/dist/esm/postgres/commands/remove.sql +0 -3
  187. package/dist/esm/postgres/commands/remove_child_dependency.sql +0 -4
  188. package/dist/esm/postgres/commands/remove_deduplication_key.sql +0 -9
  189. package/dist/esm/postgres/commands/remove_job_scheduler.sql +0 -3
  190. package/dist/esm/postgres/commands/remove_queue_meta_fields.sql +0 -2
  191. package/dist/esm/postgres/commands/remove_rate_limit.sql +0 -6
  192. package/dist/esm/postgres/commands/remove_unprocessed_children.sql +0 -3
  193. package/dist/esm/postgres/commands/reprocess_job.sql +0 -4
  194. package/dist/esm/postgres/commands/retry_job.sql +0 -3
  195. package/dist/esm/postgres/commands/retry_jobs.sql +0 -3
  196. package/dist/esm/postgres/commands/set_queue_meta.sql +0 -4
  197. package/dist/esm/postgres/commands/set_rate_limit.sql +0 -3
  198. package/dist/esm/postgres/commands/trim_logs.sql +0 -3
  199. package/dist/esm/postgres/commands/update_data.sql +0 -3
  200. package/dist/esm/postgres/commands/update_job_scheduler.sql +0 -5
  201. package/dist/esm/postgres/commands/update_progress.sql +0 -3
  202. package/dist/esm/postgres/migrations/0001_schema.sql +0 -348
  203. package/dist/esm/postgres/migrations/0002_functions.sql +0 -3473
  204. package/dist/esm/postgres/migrations/0003_dedup_stale_key.sql +0 -147
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bullmq",
3
- "version": "6.3.11",
3
+ "version": "6.3.13",
4
4
  "description": "Queue for messages and jobs based on Redis",
5
5
  "homepage": "https://bullmq.io/",
6
6
  "main": "./dist/cjs/index.js",
@@ -23,10 +23,10 @@
23
23
  "node": ">=14.17.0"
24
24
  },
25
25
  "scripts": {
26
- "build": "npm run clean:dist && npm run pretest && npm run tsc:all && npm run copy:main:type && npm run clean:temp:files && npm run copy:lua && npm run copy:includes:lua && npm run copy:sql",
26
+ "build": "npm run clean:dist && npm run pretest && npm run tsc:all && npm run copy:main:type && npm run clean:temp:files && npm run copy:lua && npm run copy:includes:lua",
27
27
  "circular:references": "madge --circular --extensions ts ./src",
28
28
  "clean:dist": "rimraf dist",
29
- "clean:scripts": "rimraf rawScripts src/scripts",
29
+ "clean:scripts": "rimraf rawScripts src/scripts src/postgres/sql-scripts.ts",
30
30
  "clean:temp:files": "rimraf dist/cjs/bullmq.d.ts dist/esm/bullmq.d.ts dist/tsdoc-metadata.json",
31
31
  "copy:includes:lua": "cpx \"./src/commands/includes/*.lua\" ./dist/cjs/commands/includes && cpx \"./src/commands/includes/*.lua\" ./dist/esm/commands/includes",
32
32
  "copy:lua": "cpx \"./src/commands/*.lua\" ./dist/cjs/commands && cpx \"./src/commands/*.lua\" ./dist/esm/commands",
@@ -52,11 +52,12 @@
52
52
  "dry-run": "npm publish --dry-run",
53
53
  "eslint:fix": "./node_modules/.bin/eslint . --fix",
54
54
  "generate:raw:scripts": "ts-node --project tsconfig-cjs.json scripts/generateRawScripts.ts",
55
+ "generate:sql:scripts": "node ./scripts/generateSqlScripts.js",
55
56
  "lint": "./node_modules/.bin/eslint .",
56
57
  "lint:staged": "lint-staged",
57
58
  "prepublishOnly": "npm run build",
58
59
  "prepare": "husky",
59
- "pretest": "npm run clean:scripts && npm run generate:raw:scripts && npm run transform:commands && npm run circular:references",
60
+ "pretest": "npm run clean:scripts && npm run generate:raw:scripts && npm run transform:commands && npm run generate:sql:scripts && npm run circular:references",
60
61
  "prettier": "prettier **/*.ts --write",
61
62
  "pretty:quick": "pretty-quick --staged",
62
63
  "semantic-release": "semantic-release",
@@ -123,7 +124,7 @@
123
124
  "@types/lodash.defaults": "4.2.9",
124
125
  "@types/lodash.isarguments": "3.1.9",
125
126
  "@types/msgpack": "0.0.34",
126
- "@types/node": "24.19.0",
127
+ "@types/node": "24.19.1",
127
128
  "@types/pg": "8.23.1",
128
129
  "@types/semver": "7.8.0",
129
130
  "@types/sinon": "22.0.0",
@@ -132,24 +133,24 @@
132
133
  "@vitest/coverage-v8": "4.1.11",
133
134
  "coveralls-next": "6.0.2",
134
135
  "cpx2": "9.0.3",
135
- "eslint": "10.11.0",
136
+ "eslint": "10.12.0",
136
137
  "eslint-config-prettier": "10.1.8",
137
138
  "eslint-plugin-prettier": "5.5.6",
138
139
  "eslint-plugin-promise": "7.3.0",
139
140
  "eslint-plugin-tsdoc": "0.5.4",
140
141
  "fast-glob": "3.3.3",
141
- "globals": "17.12.0",
142
+ "globals": "17.13.0",
142
143
  "husky": "9.1.7",
143
144
  "ioredis": "5.11.1",
144
145
  "lint-staged": "17.6.0",
145
146
  "madge": "8.0.0",
146
147
  "minimatch": "10.2.6",
147
148
  "moment": "2.31.0",
148
- "pg": "8.23.0",
149
+ "pg": "8.23.1",
149
150
  "prettier": "3.9.9",
150
151
  "pretty-quick": "4.2.2",
151
152
  "progress": "2.0.3",
152
- "redis": "6.2.1",
153
+ "redis": "6.3.0",
153
154
  "rimraf": "6.1.3",
154
155
  "rrule": "2.8.1",
155
156
  "semantic-release": "25.0.9",
@@ -1,3 +0,0 @@
1
- -- Insert a flow (tree) of jobs atomically. Param: $1 entries (jsonb array,
2
- -- ordered roots-first). Returns the job ids in input order.
3
- SELECT id FROM add_flow($1::jsonb) AS t(id);
@@ -1,5 +0,0 @@
1
- -- Insert a single job, routing it to waiting or delayed; returns its id.
2
- SELECT add_job(
3
- $1, $2, $3, $4::jsonb, $5::jsonb, $6, $7, $8, $9,
4
- $10, $11, $12, $13, $14, $15
5
- ) AS id;
@@ -1,6 +0,0 @@
1
- -- Register/update a scheduler and enqueue its next iteration; returns the
2
- -- delayed job id and its delay. Params: $1 queue, $2 scheduler_id,
3
- -- $3 next_millis, $4 template_data (jsonb), $5 template_opts (jsonb),
4
- -- $6 opts (jsonb), $7 delayed_opts (jsonb), $8 now, $9 producer_id.
5
- SELECT job_id, delay
6
- FROM add_job_scheduler($1, $2, $3, $4, $5, $6, $7, $8, $9);
@@ -1,3 +0,0 @@
1
- -- Fast set-based bulk insert of INDEPENDENT jobs (no parents, no dedup).
2
- -- Param: $1 queue, $2 entries (jsonb array). Returns the job ids in input order.
3
- SELECT id FROM add_jobs_bulk($1, $2::jsonb) AS t(id);
@@ -1,14 +0,0 @@
1
- -- Append a log line at the next per-job ordinal; returns its index.
2
- -- Params: $1 queue, $2 job_id, $3 row.
3
- -- The unqualified table name resolves in the configured BullMQ schema via
4
- -- search_path (default schema: bullmq).
5
- INSERT INTO job_log (queue, job_id, idx, row)
6
- VALUES (
7
- $1, $2,
8
- COALESCE(
9
- (SELECT MAX(idx) + 1 FROM job_log WHERE queue = $1 AND job_id = $2),
10
- 0
11
- ),
12
- $3
13
- )
14
- RETURNING idx;
@@ -1,3 +0,0 @@
1
- -- Reschedule a delayed job. Params: $1 queue, $2 id, $3 delay, $4 now.
2
- -- Returns 0 ok, -1 missing, -3 not delayed.
3
- SELECT change_delay($1, $2, $3, $4) AS code;
@@ -1,3 +0,0 @@
1
- -- Change a job's priority (and reposition via lifo). Params: $1 queue, $2 id,
2
- -- $3 priority, $4 lifo. Returns 0 ok, -1 missing.
3
- SELECT change_priority($1, $2, $3, $4) AS code;
@@ -1,3 +0,0 @@
1
- -- Remove jobs of a state older than a timestamp, up to a limit (0 = all);
2
- -- returns removed ids. Params: $1 queue, $2 type, $3 timestamp, $4 limit.
3
- SELECT id FROM clean($1, $2, $3, $4) AS t(id);
@@ -1,9 +0,0 @@
1
- -- Clear a job's logs, keeping the latest $3 entries (NULL/0 → remove all).
2
- -- Params: $1 queue, $2 job_id, $3 keepLogs.
3
- DELETE FROM job_log
4
- WHERE queue = $1 AND job_id = $2
5
- AND idx < COALESCE(
6
- (SELECT MAX(idx) FROM job_log WHERE queue = $1 AND job_id = $2)
7
- - $3 + 1,
8
- idx + 1
9
- );
@@ -1,4 +0,0 @@
1
- -- Record one finished job into the queue/kind metrics (per-minute deltas).
2
- -- Params: $1 queue, $2 kind ('completed' | 'failed'), $3 maxDataPoints,
3
- -- $4 finish timestamp (epoch ms).
4
- SELECT collect_metrics($1, $2, $3, $4);
@@ -1,6 +0,0 @@
1
- -- Unconditionally remove a deduplication key (Queue.removeDeduplicationKey /
2
- -- the deprecated removeDebounceKey). Params: $1 queue, $2 dedup_id. Returns the
3
- -- removed key (0 or 1 row).
4
- DELETE FROM dedup
5
- WHERE queue = $1 AND dedup_id = $2
6
- RETURNING dedup_id;
@@ -1,2 +0,0 @@
1
- -- Remove waiting (and optionally delayed) jobs. Params: $1 queue, $2 delayed.
2
- SELECT drain($1, $2);
@@ -1,3 +0,0 @@
1
- -- Refresh an active job's lock; returns 1 on success, 0 if the lock was lost.
2
- -- Params: $1 queue, $2 id, $3 token, $4 lock_ms, $5 now_ms.
3
- SELECT extend_lock($1, $2, $3, $4, $5) AS n;
@@ -1,25 +0,0 @@
1
- -- Refresh multiple active-job locks in one round-trip; returns the ids whose
2
- -- locks could not be renewed. Params: $1 queue, $2 ids (text[]), $3 tokens
3
- -- (text[]), $4 lock_ms, $5 now_ms.
4
- WITH input AS (
5
- SELECT ids.job_id, toks.token, ids.ord
6
- FROM unnest($2::text[]) WITH ORDINALITY AS ids(job_id, ord)
7
- JOIN unnest($3::text[]) WITH ORDINALITY AS toks(token, ord)
8
- USING (ord)
9
- ),
10
- updated AS (
11
- UPDATE job
12
- SET locked_until_ms = $5::bigint + $4::bigint
13
- FROM input
14
- WHERE queue = $1
15
- AND id = input.job_id
16
- AND state = 'active'
17
- AND lock_token = input.token
18
- RETURNING id
19
- )
20
- SELECT input.job_id AS id
21
- FROM input
22
- LEFT JOIN updated
23
- ON updated.id = input.job_id
24
- WHERE updated.id IS NULL
25
- ORDER BY input.ord;
@@ -1,11 +0,0 @@
1
- -- Connected BullMQ clients, mirroring Redis `CLIENT LIST` for worker/queue
2
- -- discovery. Each long-lived worker / QueueEvents listener names its dedicated
3
- -- connection via `application_name` (the PostgreSQL analogue of
4
- -- `CLIENT SETNAME`), so listing the named sessions on this database reproduces
5
- -- the same discovery surface. Pooled query connections leave `application_name`
6
- -- empty and are excluded. One row per connection; the backend formats them into
7
- -- `name=<application_name>` lines for the shared client-list parser.
8
- SELECT application_name
9
- FROM pg_stat_activity
10
- WHERE datname = current_database()
11
- AND application_name <> '';
@@ -1,13 +0,0 @@
1
- -- Job counts by state for a queue. Param: $1 queue.
2
- -- "prioritized" = waiting with priority > 0; "waiting" = waiting with priority 0.
3
- SELECT
4
- COUNT(*) FILTER (WHERE state = 'active') AS active,
5
- COUNT(*) FILTER (WHERE state = 'completed') AS completed,
6
- COUNT(*) FILTER (WHERE state = 'failed') AS failed,
7
- COUNT(*) FILTER (WHERE state = 'delayed') AS delayed,
8
- COUNT(*) FILTER (WHERE state = 'waiting' AND priority = 0) AS waiting,
9
- COUNT(*) FILTER (WHERE state = 'waiting' AND priority > 0) AS prioritized,
10
- COUNT(*) FILTER (WHERE state = 'waiting-children') AS "waiting-children",
11
- (SELECT value FROM meta WHERE queue = $1 AND field = 'paused') AS paused
12
- FROM job
13
- WHERE queue = $1;
@@ -1,14 +0,0 @@
1
- -- Waiting-job counts per priority. Params: $1 queue, $2 priorities (bigint[]).
2
- -- Returns one row per requested priority, in the input array order, with the
3
- -- number of waiting jobs at that priority. Pausing is an O(1) meta flag that
4
- -- leaves jobs in the 'waiting' state, so the counts are identical whether or
5
- -- not the queue is paused (mirrors Redis, where pausing does not touch the
6
- -- wait/prioritized sets).
7
- SELECT COUNT(j.id) AS cnt
8
- FROM unnest($2::bigint[]) WITH ORDINALITY AS pr(priority, ord)
9
- LEFT JOIN job j
10
- ON j.queue = $1
11
- AND j.state = 'waiting'
12
- AND j.priority = pr.priority
13
- GROUP BY pr.ord
14
- ORDER BY pr.ord;
@@ -1,7 +0,0 @@
1
- -- The current "winner" job id for a deduplication key, or none when absent or
2
- -- expired. Params: $1 queue, $2 dedup_id, $3 now (ms).
3
- SELECT job_id
4
- FROM dedup
5
- WHERE queue = $1
6
- AND dedup_id = $2
7
- AND (expire_at_ms IS NULL OR expire_at_ms > $3);
@@ -1,8 +0,0 @@
1
- -- All of a parent job's child dependencies with their status and stored value.
2
- -- Params: $1 parent_queue, $2 parent_id. Status maps to the public categories:
3
- -- processed → processed (value = return value), pending → unprocessed,
4
- -- ignored → ignored (value = reason), failed → failed.
5
- SELECT status::text AS status, child_key, value
6
- FROM job_dependency
7
- WHERE parent_queue = $1 AND parent_id = $2
8
- ORDER BY child_id;
@@ -1,7 +0,0 @@
1
- -- One page of a parent's child dependencies in a single status category.
2
- -- Params: $1 parent_queue, $2 parent_id, $3 status, $4 offset, $5 count.
3
- SELECT child_key, value
4
- FROM job_dependency
5
- WHERE parent_queue = $1 AND parent_id = $2 AND status = $3::dep_status
6
- ORDER BY child_id
7
- OFFSET $4 LIMIT $5;
@@ -1,9 +0,0 @@
1
- -- Child-dependency counts per status for a parent job.
2
- -- Params: $1 parent_queue, $2 parent_id. ("unprocessed" = pending children.)
3
- SELECT
4
- COUNT(*) FILTER (WHERE status = 'processed') AS processed,
5
- COUNT(*) FILTER (WHERE status = 'pending') AS unprocessed,
6
- COUNT(*) FILTER (WHERE status = 'ignored') AS ignored,
7
- COUNT(*) FILTER (WHERE status = 'failed') AS failed
8
- FROM job_dependency
9
- WHERE parent_queue = $1 AND parent_id = $2;
@@ -1,7 +0,0 @@
1
- -- Ignored children of a parent as (child_key → failure reason) pairs. The reason
2
- -- is stored as a JSON scalar string, so `#>> '{}'` extracts the raw text
3
- -- (mirrors the Redis `<jobId>:failed` hash). Params: $1 parent_queue, $2 parent_id.
4
- SELECT child_key, COALESCE(value #>> '{}', value::text) AS reason
5
- FROM job_dependency
6
- WHERE parent_queue = $1 AND parent_id = $2 AND status = 'ignored'
7
- ORDER BY child_id;
@@ -1,2 +0,0 @@
1
- -- A job's full row. Params: $1 queue, $2 id.
2
- SELECT * FROM job WHERE queue = $1 AND id = $2;
@@ -1,6 +0,0 @@
1
- -- A page of a job's logs, oldest first.
2
- -- Params: $1 queue, $2 job_id, $3 offset, $4 limit.
3
- SELECT row FROM job_log
4
- WHERE queue = $1 AND job_id = $2
5
- ORDER BY idx ASC
6
- OFFSET $3 LIMIT $4;
@@ -1,2 +0,0 @@
1
- -- Total number of log lines for a job. Params: $1 queue, $2 job_id.
2
- SELECT COUNT(*) AS count FROM job_log WHERE queue = $1 AND job_id = $2;
@@ -1,6 +0,0 @@
1
- -- A page of a job's logs, newest first.
2
- -- Params: $1 queue, $2 job_id, $3 offset, $4 limit.
3
- SELECT row FROM job_log
4
- WHERE queue = $1 AND job_id = $2
5
- ORDER BY idx DESC
6
- OFFSET $3 LIMIT $4;
@@ -1,6 +0,0 @@
1
- -- Fetch a single scheduler's stored metadata and next-run score.
2
- -- Params: $1 queue, $2 scheduler_id.
3
- SELECT name, iteration_count, limit_count, start_date_ms, end_date_ms, tz,
4
- pattern, every_ms, offset_ms, template_data, template_opts, next_run_ms
5
- FROM scheduler
6
- WHERE queue = $1 AND scheduler_id = $2;
@@ -1,2 +0,0 @@
1
- -- Number of registered schedulers in a queue. Param: $1 queue.
2
- SELECT count(*)::int AS count FROM scheduler WHERE queue = $1;
@@ -1,10 +0,0 @@
1
- -- Fetch a page of schedulers ordered by next-run time. Params: $1 queue,
2
- -- $2 asc (boolean), $3 offset, $4 count (NULL = all remaining).
3
- SELECT scheduler_id, next_run_ms
4
- FROM scheduler
5
- WHERE queue = $1
6
- ORDER BY CASE WHEN $2 THEN next_run_ms END ASC,
7
- CASE WHEN NOT $2 THEN next_run_ms END DESC,
8
- scheduler_id
9
- OFFSET $3
10
- LIMIT $4;
@@ -1,14 +0,0 @@
1
- -- Metrics for a queue/kind: the cumulative meta `count` and the per-minute data
2
- -- points (newest first), sliced to [start, end] with Redis LRANGE semantics
3
- -- (index 0 is the newest point; a negative end means "to the oldest").
4
- -- Params: $1 queue, $2 kind ('completed' | 'failed'), $3 start, $4 end.
5
- SELECT
6
- COALESCE((SELECT count FROM metrics
7
- WHERE queue = $1 AND kind = $2), 0)::bigint AS total,
8
- COALESCE((
9
- SELECT CASE
10
- WHEN $4 < 0 THEN data[($3 + 1) : ]
11
- ELSE data[($3 + 1) : ($4 + 1)]
12
- END
13
- FROM metrics WHERE queue = $1 AND kind = $2
14
- ), ARRAY[]::bigint[]) AS data;
@@ -1,8 +0,0 @@
1
- -- Processed children of a parent as (child_key → serialized value) pairs. The
2
- -- value is returned as JSON text so the caller can JSON.parse it (mirrors the
3
- -- Redis `<jobId>:processed` hash of stringified values). Params: $1 parent_queue,
4
- -- $2 parent_id.
5
- SELECT child_key, value::text AS value
6
- FROM job_dependency
7
- WHERE parent_queue = $1 AND parent_id = $2 AND status = 'processed'
8
- ORDER BY child_id;
@@ -1,2 +0,0 @@
1
- -- The full queue metadata hash. Param: $1 queue.
2
- SELECT field, value FROM meta WHERE queue = $1;
@@ -1,2 +0,0 @@
1
- -- A single queue metadata field's value. Params: $1 queue, $2 field.
2
- SELECT value FROM meta WHERE queue = $1 AND field = $2;
@@ -1,3 +0,0 @@
1
- -- Several queue metadata fields. Params: $1 queue, $2 fields (text[]).
2
- SELECT field, value FROM meta
3
- WHERE queue = $1 AND field = ANY($2::text[]);
@@ -1,3 +0,0 @@
1
- -- Job ids in a state, sliced by [start, end]. Params: $1 queue, $2 type,
2
- -- $3 start, $4 end, $5 asc.
3
- SELECT id FROM get_range($1, $2, $3, $4, $5) AS t(id);
@@ -1,3 +0,0 @@
1
- -- Current rate-limit ttl in ms (Redis getRateLimitTtl semantics). Params:
2
- -- $1 queue, $2 maxJobs (0 = unspecified → meta `max` / raw window), $3 now_ms.
3
- SELECT rate_limit_ttl($1, $2, $3) AS ttl;
@@ -1,2 +0,0 @@
1
- -- A job's state and priority. Params: $1 queue, $2 id.
2
- SELECT state, priority FROM job WHERE queue = $1 AND id = $2;
@@ -1,4 +0,0 @@
1
- -- Whether a queue metadata field exists. Params: $1 queue, $2 field.
2
- SELECT EXISTS(
3
- SELECT 1 FROM meta WHERE queue = $1 AND field = $2
4
- ) AS exists;
@@ -1,11 +0,0 @@
1
- -- Whether the queue has a claimable (waiting, non-paused) job right now. Used
2
- -- by waitForJob to close the race where a NOTIFY fires before the listener is
3
- -- established (mirrors the atomicity of Redis's blocking pop). Param: $1 queue.
4
- SELECT
5
- EXISTS(
6
- SELECT 1 FROM job WHERE queue = $1 AND state = 'waiting'
7
- )
8
- AND NOT EXISTS(
9
- SELECT 1 FROM meta
10
- WHERE queue = $1 AND field = 'paused' AND value = '1'
11
- ) AS present;
@@ -1,4 +0,0 @@
1
- -- A job's finished state and result/reason (for waitUntilFinished / isFinished).
2
- -- Params: $1 queue, $2 id.
3
- SELECT state, return_value, failed_reason
4
- FROM job WHERE queue = $1 AND id = $2;
@@ -1,6 +0,0 @@
1
- -- Whether a job is currently in the given state. Params: $1 queue, $2 id,
2
- -- $3 state.
3
- SELECT EXISTS(
4
- SELECT 1 FROM job
5
- WHERE queue = $1 AND id = $2 AND state = $3::job_state
6
- ) AS present;
@@ -1,15 +0,0 @@
1
- -- Whether a (non-prioritized) waiting job is in the wait or paused list. The
2
- -- queue has no separate paused list: a waiting job belongs to the paused list
3
- -- when the queue is paused, and to the wait list otherwise. $3 selects which
4
- -- list to test (true = paused, false = wait). Params: $1 queue, $2 id, $3 paused.
5
- SELECT EXISTS(
6
- SELECT 1 FROM job j
7
- WHERE j.queue = $1 AND j.id = $2
8
- AND j.state = 'waiting' AND j.priority = 0
9
- AND (
10
- EXISTS(
11
- SELECT 1 FROM meta m
12
- WHERE m.queue = $1 AND m.field = 'paused' AND m.value = '1'
13
- )
14
- ) = $3
15
- ) AS present;
@@ -1,6 +0,0 @@
1
- -- Whether a job is prioritized (waiting with a non-zero priority).
2
- -- Params: $1 queue, $2 id.
3
- SELECT EXISTS(
4
- SELECT 1 FROM job
5
- WHERE queue = $1 AND id = $2 AND state = 'waiting' AND priority > 0
6
- ) AS present;
@@ -1,4 +0,0 @@
1
- -- Whether an id corresponds to a registered scheduler. Params: $1 queue, $2 id.
2
- SELECT EXISTS (
3
- SELECT 1 FROM scheduler WHERE queue = $1 AND scheduler_id = $2
4
- ) AS exists;
@@ -1,10 +0,0 @@
1
- -- Whether the queue is "maxed": it has a global concurrency limit and the
2
- -- number of active jobs has reached it (mirrors isQueueMaxed). Returns false
3
- -- when no concurrency limit is configured.
4
- -- Params: $1 queue.
5
- SELECT COALESCE(
6
- (SELECT count(*) FROM job WHERE queue = $1 AND state = 'active')
7
- >= (SELECT value::integer FROM meta
8
- WHERE queue = $1 AND field = 'concurrency'),
9
- false
10
- ) AS maxed;
@@ -1,3 +0,0 @@
1
- -- Subscribe to the shared event-stream channel. Producers
2
- -- `pg_notify('bullmq_events', <queue>)`; a consumer filters for its own queue.
3
- LISTEN bullmq_events;
@@ -1,4 +0,0 @@
1
- -- Subscribe to the shared job-notification channel (fixed name keeps this
2
- -- portable). Producers `pg_notify('bullmq_jobs', <queue>)`; a worker filters
3
- -- notifications for its own queue.
4
- LISTEN bullmq_jobs;
@@ -1,4 +0,0 @@
1
- -- Move an active job back to wait (Job.moveToWait / dynamic rate limit).
2
- -- Params: $1 queue, $2 id, $3 token ('0' bypasses the lock check), $4 now_ms.
3
- -- Returns the limiter window ms (>=0), or -1 when the job no longer exists.
4
- SELECT move_active_to_wait($1, $2, $3, $4) AS n;
@@ -1,4 +0,0 @@
1
- -- Two-phase stalled-job recovery (mark on one pass, reclaim on the next);
2
- -- returns the reclaimed ids. Params: $1 queue, $2 max_stalled_count,
3
- -- $3 now_ms, $4 max_check_time_ms (stalledInterval).
4
- SELECT id FROM move_stalled_jobs_to_wait($1, $2, $3, $4) AS t(id);
@@ -1,4 +0,0 @@
1
- -- Claim the next ready job for a worker (0 or 1 rows), honouring the limiter.
2
- -- Params: $1 queue, $2 token, $3 lock_ms, $4 now_ms, $5 worker name,
3
- -- $6 limiter max (worker option, NULL if none), $7 limiter duration ms.
4
- SELECT * FROM move_to_active($1, $2, $3, $4, $5, $6, $7);
@@ -1,4 +0,0 @@
1
- -- Finish an active job successfully; returns the finished-at timestamp.
2
- -- Params: $1 queue, $2 id, $3 token, $4 return_value (jsonb), $5 finished_on,
3
- -- $6 remove_all, $7 keep_age (s), $8 keep_count.
4
- SELECT move_to_completed($1, $2, $3, $4::jsonb, $5, $6, $7, $8) AS finished_on;
@@ -1,9 +0,0 @@
1
- -- Finish an active job successfully AND claim the next ready job in one
2
- -- transaction (one commit) — the fused equivalent of move_to_completed followed
3
- -- by move_to_active, mirroring Redis's moveToFinished. Returns 0 or 1 job rows.
4
- -- Params: $1 queue, $2 id, $3 token, $4 return_value (jsonb), $5 finished_on,
5
- -- $6 remove_all, $7 keep_age (s), $8 keep_count,
6
- -- $9 lock_ms, $10 now_ms, $11 worker name,
7
- -- $12 limiter max (worker option, NULL if none), $13 limiter duration ms.
8
- SELECT * FROM move_to_completed_fetch(
9
- $1, $2, $3, $4::jsonb, $5, $6, $7, $8, $9, $10, $11, $12, $13);
@@ -1,4 +0,0 @@
1
- -- Re-queue an active job to the delayed state (retry-with-delay / manual delay).
2
- -- Params: $1 queue, $2 id, $3 token, $4 process_at, $5 delay,
3
- -- $6 skip_attempt, $7 failed_reason, $8 stacktrace (jsonb).
4
- SELECT move_to_delayed($1, $2, $3, $4, $5, $6, $7, $8::jsonb) AS n;
@@ -1,4 +0,0 @@
1
- -- Mark an active job failed; returns the finished-at timestamp.
2
- -- Params: $1 queue, $2 id, $3 token, $4 failed_reason, $5 stacktrace (jsonb),
3
- -- $6 finished_on, $7 remove_all, $8 keep_age (s), $9 keep_count.
4
- SELECT move_to_failed($1, $2, $3, $4, $5::jsonb, $6, $7, $8, $9) AS finished_on;
@@ -1,9 +0,0 @@
1
- -- Fail (or retry) an active job AND claim the next ready job in one transaction
2
- -- (one commit) — the fused equivalent of move_to_failed followed by
3
- -- move_to_active, mirroring Redis's moveToFinished. Returns 0 or 1 job rows.
4
- -- Params: $1 queue, $2 id, $3 token, $4 failed_reason, $5 stacktrace (jsonb),
5
- -- $6 finished_on, $7 remove_all, $8 keep_age (s), $9 keep_count,
6
- -- $10 lock_ms, $11 now_ms, $12 worker name,
7
- -- $13 limiter max (worker option, NULL if none), $14 limiter duration ms.
8
- SELECT * FROM move_to_failed_fetch(
9
- $1, $2, $3, $4, $5::jsonb, $6, $7, $8, $9, $10, $11, $12, $13, $14);
@@ -1,3 +0,0 @@
1
- -- Move an active parent to waiting-children if it has pending children.
2
- -- Params: $1 queue, $2 id, $3 token. Returns 1 (should wait), 0 (proceed).
3
- SELECT move_to_waiting_children($1, $2, $3) AS code;
@@ -1,2 +0,0 @@
1
- -- The timestamp of the next delayed job, or NULL if there are none.
2
- SELECT next_delay($1) AS next_delay;
@@ -1,3 +0,0 @@
1
- -- The worker "no job" signal: effective rate-limit ttl + next delayed-job time.
2
- -- Params: $1 queue, $2 limiter max (worker option, NULL if none), $3 now_ms.
3
- SELECT rate_limit_ttl, next_delay FROM next_signal($1, $2, $3);
@@ -1,4 +0,0 @@
1
- -- Obliterate a queue: delete up to $2 jobs; returns -1 (not paused), -2 (active
2
- -- jobs without force), 1 (more to delete), or 0 (done). Params: $1 queue,
3
- -- $2 count, $3 force.
4
- SELECT obliterate($1, $2, $3) AS cursor;
@@ -1,19 +0,0 @@
1
- -- A parent job's child dependencies of a given status, sliced [offset, limit]
2
- -- and joined to the child job rows (for fetchJobs). Params: $1 parent_queue,
3
- -- $2 parent_id, $3 status ('pending' | 'processed'), $4 offset, $5 limit
4
- -- (NULL = no limit). `total` is the full number of matching dependencies
5
- -- (COUNT(*) OVER(), computed before the slice). `dep_value` is the stored
6
- -- result for processed children. The remaining columns are the child
7
- -- `job` row consumed by rowToJobJson.
8
- SELECT
9
- d.child_key,
10
- d.value AS dep_value,
11
- COUNT(*) OVER() AS total,
12
- j.*
13
- FROM job_dependency d
14
- LEFT JOIN job j
15
- ON j.queue = d.child_queue AND j.id = d.child_id
16
- WHERE d.parent_queue = $1 AND d.parent_id = $2 AND d.status = $3::dep_status
17
- ORDER BY d.child_key
18
- OFFSET $4
19
- LIMIT $5;
@@ -1,2 +0,0 @@
1
- -- Pause/resume the queue. Params: $1 queue, $2 paused.
2
- SELECT pause($1, $2);
@@ -1,3 +0,0 @@
1
- -- Promote a delayed job to waiting. Params: $1 queue, $2 id.
2
- -- Returns 0 ok, -1 missing, -3 not delayed.
3
- SELECT promote($1, $2) AS code;
@@ -1,3 +0,0 @@
1
- -- Move up to `count` delayed jobs to waiting; returns the number moved.
2
- -- Params: $1 queue, $2 count.
3
- SELECT promote_jobs($1, $2) AS n;
@@ -1,3 +0,0 @@
1
- -- Append a custom event to the stream; returns the event id.
2
- -- Params: $1 queue, $2 event, $3 data (jsonb).
3
- SELECT publish_event($1, $2, $3::jsonb) AS id;
@@ -1,6 +0,0 @@
1
- -- A page of events newer than a cursor, oldest first.
2
- -- Params: $1 queue, $2 cursor (exclusive), $3 limit.
3
- SELECT id, event, data FROM event
4
- WHERE queue = $1 AND id > $2
5
- ORDER BY id ASC
6
- LIMIT $3;
@@ -1,3 +0,0 @@
1
- -- The current max event id for a queue (used to resolve the '$' cursor).
2
- -- Param: $1 queue.
3
- SELECT COALESCE(MAX(id), 0)::bigint AS max FROM event WHERE queue = $1;
@@ -1,3 +0,0 @@
1
- -- Remove a job (and optionally its children). Returns 1 if removed, else 0.
2
- -- Params: $1 queue, $2 id, $3 remove_children.
3
- SELECT remove($1, $2, $3) AS n;
@@ -1,4 +0,0 @@
1
- -- Break a child's dependency link to its parent. Params: $1 queue, $2 job_id,
2
- -- $3 parent_key, $4 now. Returns 0 (removed) or 1 (no relationship); raises on
3
- -- missing job (-1) / missing parent (-5).
4
- SELECT remove_child_dependency($1, $2, $3, $4) AS n;