bunqueue 2.8.54 → 2.8.57

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 (718) hide show
  1. package/dist/application/background/dlq.d.ts +2 -0
  2. package/dist/application/background/dlq.js +26 -0
  3. package/dist/application/background/lifecycle.d.ts +4 -0
  4. package/dist/application/background/lifecycle.js +90 -0
  5. package/dist/application/background/recovery/active.d.ts +4 -0
  6. package/dist/application/background/recovery/active.js +69 -0
  7. package/dist/application/background/recovery/index.d.ts +2 -0
  8. package/dist/application/background/recovery/index.js +22 -0
  9. package/dist/application/background/recovery/pending.d.ts +3 -0
  10. package/dist/application/background/recovery/pending.js +69 -0
  11. package/dist/application/background/recovery/restore.d.ts +5 -0
  12. package/dist/application/background/recovery/restore.js +58 -0
  13. package/dist/application/background/recovery/shared.d.ts +6 -0
  14. package/dist/application/background/recovery/shared.js +15 -0
  15. package/dist/application/background/timeouts.d.ts +25 -0
  16. package/dist/application/background/timeouts.js +191 -0
  17. package/dist/application/backgroundTasks.d.ts +7 -31
  18. package/dist/application/backgroundTasks.js +6 -442
  19. package/dist/application/cleanupTasks.js +1 -0
  20. package/dist/application/clientTracking.js +2 -0
  21. package/dist/application/contextFactory.d.ts +13 -90
  22. package/dist/application/contextFactory.js +8 -0
  23. package/dist/application/dependencyResultTracker.d.ts +1 -0
  24. package/dist/application/dependencyResultTracker.js +3 -0
  25. package/dist/application/dlqManager.d.ts +2 -8
  26. package/dist/application/dlqManager.js +33 -162
  27. package/dist/application/dlqRetry.d.ts +12 -0
  28. package/dist/application/dlqRetry.js +97 -0
  29. package/dist/application/lockManager.js +21 -1
  30. package/dist/application/lockOperations.js +16 -3
  31. package/dist/application/operations/ack/batch.d.ts +8 -0
  32. package/dist/application/operations/ack/batch.js +64 -0
  33. package/dist/application/operations/ack/completion.d.ts +3 -0
  34. package/dist/application/operations/ack/completion.js +74 -0
  35. package/dist/application/operations/ack/failure.d.ts +3 -0
  36. package/dist/application/operations/ack/failure.js +160 -0
  37. package/dist/application/operations/ack.d.ts +5 -79
  38. package/dist/application/operations/ack.js +4 -319
  39. package/dist/application/operations/ackHelpers.d.ts +3 -52
  40. package/dist/application/operations/ackHelpers.js +10 -3
  41. package/dist/application/operations/customId.d.ts +18 -5
  42. package/dist/application/operations/customId.js +36 -25
  43. package/dist/application/operations/flowValidation.js +9 -4
  44. package/dist/application/operations/jobManagement.js +44 -7
  45. package/dist/application/operations/parentLink.d.ts +36 -0
  46. package/dist/application/operations/parentLink.js +153 -0
  47. package/dist/application/operations/parentLinkInput.d.ts +8 -0
  48. package/dist/application/operations/parentLinkInput.js +23 -0
  49. package/dist/application/operations/push.d.ts +5 -44
  50. package/dist/application/operations/push.js +62 -152
  51. package/dist/application/operations/pushAdmission.d.ts +32 -0
  52. package/dist/application/operations/pushAdmission.js +38 -0
  53. package/dist/application/operations/pushBatch.d.ts +4 -0
  54. package/dist/application/operations/pushBatch.js +136 -0
  55. package/dist/application/operations/pushContext.d.ts +39 -0
  56. package/dist/application/operations/pushContext.js +1 -0
  57. package/dist/application/operations/pushDeduplication.d.ts +42 -0
  58. package/dist/application/operations/pushDeduplication.js +131 -0
  59. package/dist/application/operations/pushInsert.d.ts +13 -1
  60. package/dist/application/operations/pushInsert.js +33 -17
  61. package/dist/application/operations/pushLocks.js +13 -9
  62. package/dist/application/operations/query/collect.d.ts +12 -0
  63. package/dist/application/operations/query/collect.js +118 -0
  64. package/dist/application/operations/query/jobLookup.d.ts +9 -0
  65. package/dist/application/operations/query/jobLookup.js +110 -0
  66. package/dist/application/operations/query/pagination.d.ts +8 -0
  67. package/dist/application/operations/query/pagination.js +90 -0
  68. package/dist/application/operations/query/state.d.ts +4 -0
  69. package/dist/application/operations/query/state.js +63 -0
  70. package/dist/application/operations/queryOperations.d.ts +5 -50
  71. package/dist/application/operations/queryOperations.js +4 -474
  72. package/dist/application/queue-manager/ack.d.ts +23 -0
  73. package/dist/application/queue-manager/ack.js +242 -0
  74. package/dist/application/queue-manager/configuration.d.ts +27 -0
  75. package/dist/application/queue-manager/configuration.js +84 -0
  76. package/dist/application/queue-manager/context.d.ts +5 -0
  77. package/dist/application/queue-manager/context.js +61 -0
  78. package/dist/application/queue-manager/control.d.ts +17 -0
  79. package/dist/application/queue-manager/control.js +133 -0
  80. package/dist/application/queue-manager/delivery.d.ts +32 -0
  81. package/dist/application/queue-manager/delivery.js +143 -0
  82. package/dist/application/queue-manager/dependencies.d.ts +8 -0
  83. package/dist/application/queue-manager/dependencies.js +127 -0
  84. package/dist/application/queue-manager/dependency-runtime.d.ts +8 -0
  85. package/dist/application/queue-manager/dependency-runtime.js +40 -0
  86. package/dist/application/queue-manager/flow-failures.d.ts +18 -0
  87. package/dist/application/queue-manager/flow-failures.js +107 -0
  88. package/dist/application/queue-manager/flow-options.d.ts +8 -0
  89. package/dist/application/queue-manager/flow-options.js +129 -0
  90. package/dist/application/queue-manager/job-management.d.ts +17 -0
  91. package/dist/application/queue-manager/job-management.js +100 -0
  92. package/dist/application/queue-manager/lifecycle.d.ts +4 -0
  93. package/dist/application/queue-manager/lifecycle.js +41 -0
  94. package/dist/application/queue-manager/limits.d.ts +41 -0
  95. package/dist/application/queue-manager/limits.js +108 -0
  96. package/dist/application/queue-manager/locks.d.ts +21 -0
  97. package/dist/application/queue-manager/locks.js +59 -0
  98. package/dist/application/queue-manager/observability.d.ts +16 -0
  99. package/dist/application/queue-manager/observability.js +44 -0
  100. package/dist/application/queue-manager/queries.d.ts +17 -0
  101. package/dist/application/queue-manager/queries.js +118 -0
  102. package/dist/application/queue-manager/repeat.d.ts +4 -0
  103. package/dist/application/queue-manager/repeat.js +26 -0
  104. package/dist/application/queue-manager/services.d.ts +19 -0
  105. package/dist/application/queue-manager/services.js +80 -0
  106. package/dist/application/queue-manager/state.d.ts +92 -0
  107. package/dist/application/queue-manager/state.js +144 -0
  108. package/dist/application/queue-manager/stats.d.ts +28 -0
  109. package/dist/application/queue-manager/stats.js +52 -0
  110. package/dist/application/queueManager.d.ts +4 -400
  111. package/dist/application/queueManager.js +3 -1922
  112. package/dist/application/queueTelemetryJournal.d.ts +20 -0
  113. package/dist/application/queueTelemetryJournal.js +133 -0
  114. package/dist/application/repeatJobs.d.ts +7 -0
  115. package/dist/application/repeatJobs.js +132 -0
  116. package/dist/application/stallDetection.js +6 -1
  117. package/dist/application/types/ack.d.ts +132 -0
  118. package/dist/application/types/ack.js +1 -0
  119. package/dist/application/types/background.d.ts +18 -0
  120. package/dist/application/types/background.js +1 -0
  121. package/dist/application/types/config.d.ts +37 -0
  122. package/dist/application/{types.js → types/config.js} +3 -4
  123. package/dist/application/types/contextFactory.d.ts +83 -0
  124. package/dist/application/types/contextFactory.js +1 -0
  125. package/dist/application/types/contexts.d.ts +110 -0
  126. package/dist/application/types/contexts.js +1 -0
  127. package/dist/application/types/index.d.ts +7 -0
  128. package/dist/application/types/index.js +1 -0
  129. package/dist/application/types/query.d.ts +23 -0
  130. package/dist/application/types/query.js +1 -0
  131. package/dist/application/types/queueManager.d.ts +94 -0
  132. package/dist/application/types/queueManager.js +1 -0
  133. package/dist/cli/commandRouter.d.ts +1 -1
  134. package/dist/cli/commands/core.js +1 -0
  135. package/dist/cli/output/collections.d.ts +8 -0
  136. package/dist/cli/output/collections.js +131 -0
  137. package/dist/cli/output/jobs.d.ts +2 -0
  138. package/dist/cli/output/jobs.js +61 -0
  139. package/dist/cli/output/style.d.ts +14 -0
  140. package/dist/cli/output/style.js +28 -0
  141. package/dist/cli/output/success.d.ts +1 -0
  142. package/dist/cli/output/success.js +108 -0
  143. package/dist/cli/output.d.ts +1 -6
  144. package/dist/cli/output.js +7 -395
  145. package/dist/client/bunqueue/dlqRateLimit.d.ts +8 -0
  146. package/dist/client/bunqueue/dlqRateLimit.js +24 -0
  147. package/dist/client/bunqueue/runtime.d.ts +35 -0
  148. package/dist/client/bunqueue/runtime.js +138 -0
  149. package/dist/client/bunqueue.d.ts +19 -34
  150. package/dist/client/bunqueue.js +45 -166
  151. package/dist/client/dlqConversion.d.ts +5 -0
  152. package/dist/client/dlqConversion.js +28 -0
  153. package/dist/client/events.d.ts +7 -56
  154. package/dist/client/events.js +38 -15
  155. package/dist/client/flow.d.ts +6 -12
  156. package/dist/client/flow.js +16 -34
  157. package/dist/client/flowJobFactory.d.ts +9 -1
  158. package/dist/client/flowJobFactory.js +25 -9
  159. package/dist/client/flowJobMoveMethods.d.ts +5 -5
  160. package/dist/client/flowJobMoveMethods.js +31 -16
  161. package/dist/client/flowLegacyPlan.js +22 -8
  162. package/dist/client/flowOptions.d.ts +1 -1
  163. package/dist/client/flowOptions.js +2 -1
  164. package/dist/client/flowPlan.js +2 -3
  165. package/dist/client/flowPush.d.ts +1 -0
  166. package/dist/client/flowPush.js +5 -1
  167. package/dist/client/flowReader.js +5 -5
  168. package/dist/client/flowResults.d.ts +11 -0
  169. package/dist/client/flowResults.js +42 -0
  170. package/dist/client/index.d.ts +3 -1
  171. package/dist/client/jobConversion.d.ts +0 -4
  172. package/dist/client/jobConversion.js +32 -33
  173. package/dist/client/jobConversionHelpers.d.ts +18 -2
  174. package/dist/client/jobConversionHelpers.js +17 -10
  175. package/dist/client/jobConversionTypes.d.ts +5 -1
  176. package/dist/client/jobHelpers.d.ts +7 -2
  177. package/dist/client/jobHelpers.js +16 -8
  178. package/dist/client/queue/dlq.js +12 -14
  179. package/dist/client/queue/dlqJobMethods.js +11 -10
  180. package/dist/client/queue/dlqOps.js +2 -8
  181. package/dist/client/queue/dlqStats.d.ts +3 -0
  182. package/dist/client/queue/dlqStats.js +21 -0
  183. package/dist/client/queue/job-proxy/dependencies.d.ts +9 -0
  184. package/dist/client/queue/job-proxy/dependencies.js +67 -0
  185. package/dist/client/queue/job-proxy/reflection.d.ts +2 -0
  186. package/dist/client/queue/job-proxy/reflection.js +18 -0
  187. package/dist/client/queue/job-proxy/simple.d.ts +3 -0
  188. package/dist/client/queue/job-proxy/simple.js +316 -0
  189. package/dist/client/queue/job-proxy/tcp.d.ts +4 -0
  190. package/dist/client/queue/job-proxy/tcp.js +191 -0
  191. package/dist/client/queue/jobMetadata.d.ts +10 -0
  192. package/dist/client/queue/jobMetadata.js +24 -0
  193. package/dist/client/queue/jobMove.d.ts +4 -4
  194. package/dist/client/queue/jobMove.js +82 -24
  195. package/dist/client/queue/jobProxy.d.ts +4 -50
  196. package/dist/client/queue/jobProxy.js +3 -516
  197. package/dist/client/queue/operations/add/bulk.d.ts +7 -0
  198. package/dist/client/queue/operations/add/bulk.js +129 -0
  199. package/dist/client/queue/operations/add/payload.d.ts +24 -0
  200. package/dist/client/queue/operations/add/payload.js +85 -0
  201. package/dist/client/queue/operations/add/single.d.ts +3 -0
  202. package/dist/client/queue/operations/add/single.js +107 -0
  203. package/dist/client/queue/operations/add.d.ts +2 -47
  204. package/dist/client/queue/operations/add.js +2 -364
  205. package/dist/client/queue/operations/management.js +2 -1
  206. package/dist/client/queue/operations/query.js +20 -63
  207. package/dist/client/queue/queue.d.ts +6 -192
  208. package/dist/client/queue/queue.js +6 -559
  209. package/dist/client/queue/runtime/compatibility.d.ts +13 -0
  210. package/dist/client/queue/runtime/compatibility.js +38 -0
  211. package/dist/client/queue/runtime/configuration.d.ts +42 -0
  212. package/dist/client/queue/runtime/configuration.js +109 -0
  213. package/dist/client/queue/runtime/connection.d.ts +6 -0
  214. package/dist/client/queue/runtime/connection.js +16 -0
  215. package/dist/client/queue/runtime/control.d.ts +41 -0
  216. package/dist/client/queue/runtime/control.js +87 -0
  217. package/dist/client/queue/runtime/queries.d.ts +48 -0
  218. package/dist/client/queue/runtime/queries.js +95 -0
  219. package/dist/client/queue/runtime/scheduling.d.ts +33 -0
  220. package/dist/client/queue/runtime/scheduling.js +56 -0
  221. package/dist/client/queue/runtime/state.d.ts +96 -0
  222. package/dist/client/queue/runtime/state.js +149 -0
  223. package/dist/client/queue/scheduler.d.ts +2 -5
  224. package/dist/client/queue/scheduler.js +25 -23
  225. package/dist/client/queue/schedulerPagination.d.ts +7 -0
  226. package/dist/client/queue/schedulerPagination.js +10 -0
  227. package/dist/client/queue/types/add.d.ts +40 -0
  228. package/dist/client/queue/types/add.js +1 -0
  229. package/dist/client/queue/{queueTypes.d.ts → types/contexts.d.ts} +2 -2
  230. package/dist/client/queue/types/index.d.ts +3 -0
  231. package/dist/client/queue/types/index.js +1 -0
  232. package/dist/client/queue/types/job.d.ts +50 -0
  233. package/dist/client/queue/types/job.js +1 -0
  234. package/dist/client/queue/types/runtime.d.ts +35 -0
  235. package/dist/client/queue/types/runtime.js +1 -0
  236. package/dist/client/queue/workers.d.ts +4 -8
  237. package/dist/client/queue/workers.js +22 -14
  238. package/dist/client/queue-events/tcpSubscription.d.ts +23 -0
  239. package/dist/client/queue-events/tcpSubscription.js +99 -0
  240. package/dist/client/sandboxed/queueOps.d.ts +2 -2
  241. package/dist/client/sandboxed/queueOps.js +32 -5
  242. package/dist/client/sandboxed/runtime/dispatch.d.ts +13 -0
  243. package/dist/client/sandboxed/runtime/dispatch.js +186 -0
  244. package/dist/client/sandboxed/runtime/lifecycle.d.ts +20 -0
  245. package/dist/client/sandboxed/runtime/lifecycle.js +95 -0
  246. package/dist/client/sandboxed/runtime/log.d.ts +1 -0
  247. package/dist/client/sandboxed/runtime/log.js +15 -0
  248. package/dist/client/sandboxed/runtime/pool.d.ts +11 -0
  249. package/dist/client/sandboxed/runtime/pool.js +121 -0
  250. package/dist/client/sandboxed/runtime/recovery.d.ts +11 -0
  251. package/dist/client/sandboxed/runtime/recovery.js +122 -0
  252. package/dist/client/sandboxed/runtime/state.d.ts +39 -0
  253. package/dist/client/sandboxed/runtime/state.js +59 -0
  254. package/dist/client/sandboxed/types/index.d.ts +2 -0
  255. package/dist/client/sandboxed/types/index.js +1 -0
  256. package/dist/client/sandboxed/types/options.d.ts +27 -0
  257. package/dist/client/sandboxed/types/options.js +1 -0
  258. package/dist/client/sandboxed/types/process.d.ts +30 -0
  259. package/dist/client/sandboxed/types/process.js +1 -0
  260. package/dist/client/sandboxed/worker.d.ts +3 -85
  261. package/dist/client/sandboxed/worker.js +3 -557
  262. package/dist/client/sandboxed/wrapper.js +1 -0
  263. package/dist/client/tcp/client.d.ts +5 -112
  264. package/dist/client/tcp/client.js +5 -481
  265. package/dist/client/tcp/commandQueue.d.ts +23 -0
  266. package/dist/client/tcp/commandQueue.js +89 -0
  267. package/dist/client/tcp/connection.d.ts +4 -85
  268. package/dist/client/tcp/connection.js +3 -315
  269. package/dist/client/tcp/errors.d.ts +6 -0
  270. package/dist/client/tcp/errors.js +18 -0
  271. package/dist/client/tcp/runtime/commands.d.ts +9 -0
  272. package/dist/client/tcp/runtime/commands.js +124 -0
  273. package/dist/client/tcp/runtime/connectivity.d.ts +13 -0
  274. package/dist/client/tcp/runtime/connectivity.js +77 -0
  275. package/dist/client/tcp/runtime/health.d.ts +14 -0
  276. package/dist/client/tcp/runtime/health.js +127 -0
  277. package/dist/client/tcp/runtime/lifecycle.d.ts +8 -0
  278. package/dist/client/tcp/runtime/lifecycle.js +32 -0
  279. package/dist/client/tcp/runtime/state.d.ts +50 -0
  280. package/dist/client/tcp/runtime/state.js +45 -0
  281. package/dist/client/tcp/transport.d.ts +18 -0
  282. package/dist/client/tcp/transport.js +158 -0
  283. package/dist/client/tcp/types/command.d.ts +9 -0
  284. package/dist/client/tcp/types/command.js +1 -0
  285. package/dist/client/tcp/types/connection.d.ts +31 -0
  286. package/dist/client/tcp/types/connection.js +17 -0
  287. package/dist/client/tcp/types/index.d.ts +5 -0
  288. package/dist/client/tcp/types/index.js +1 -0
  289. package/dist/client/tcp/types/socket.d.ts +8 -0
  290. package/dist/client/tcp/types/socket.js +1 -0
  291. package/dist/client/tcp/types/tls.d.ts +4 -0
  292. package/dist/client/tcp/types/tls.js +1 -0
  293. package/dist/client/tcp/types.d.ts +2 -106
  294. package/dist/client/tcp/types.js +2 -22
  295. package/dist/client/types/connection.d.ts +29 -0
  296. package/dist/client/types/connection.js +1 -0
  297. package/dist/client/types/dlq.d.ts +45 -0
  298. package/dist/client/types/dlq.js +1 -0
  299. package/dist/client/types/events.d.ts +54 -0
  300. package/dist/client/types/events.js +1 -0
  301. package/dist/client/types/flow.d.ts +10 -0
  302. package/dist/client/types/flow.js +1 -0
  303. package/dist/client/types/index.d.ts +10 -0
  304. package/dist/client/types/index.js +1 -0
  305. package/dist/client/types/job.d.ts +127 -0
  306. package/dist/client/types/job.js +1 -0
  307. package/dist/client/types/metrics.d.ts +1 -0
  308. package/dist/client/types/metrics.js +1 -0
  309. package/dist/client/types/options.d.ts +62 -0
  310. package/dist/client/types/options.js +1 -0
  311. package/dist/client/types/worker.d.ts +38 -0
  312. package/dist/client/types/worker.js +1 -0
  313. package/dist/client/types.d.ts +2 -583
  314. package/dist/client/types.js +2 -6
  315. package/dist/client/worker/ackBatcher.d.ts +1 -1
  316. package/dist/client/worker/ackBatcher.js +17 -5
  317. package/dist/client/worker/ackOutcome.d.ts +8 -0
  318. package/dist/client/worker/ackOutcome.js +58 -0
  319. package/dist/client/worker/constants.d.ts +7 -0
  320. package/dist/client/worker/{types.js → constants.js} +0 -6
  321. package/dist/client/worker/groupConcurrency.js +3 -0
  322. package/dist/client/worker/handlers/completion.d.ts +28 -0
  323. package/dist/client/worker/handlers/completion.js +68 -0
  324. package/dist/client/worker/handlers/dependencies.d.ts +11 -0
  325. package/dist/client/worker/handlers/dependencies.js +107 -0
  326. package/dist/client/worker/handlers/mutations.d.ts +23 -0
  327. package/dist/client/worker/handlers/mutations.js +211 -0
  328. package/dist/client/worker/handlers/queries.d.ts +15 -0
  329. package/dist/client/worker/handlers/queries.js +100 -0
  330. package/dist/client/worker/index.d.ts +2 -2
  331. package/dist/client/worker/index.js +1 -1
  332. package/dist/client/worker/jobParser.js +4 -2
  333. package/dist/client/worker/processor.d.ts +2 -15
  334. package/dist/client/worker/processor.js +67 -124
  335. package/dist/client/worker/processorHandlers.d.ts +4 -61
  336. package/dist/client/worker/processorHandlers.js +4 -398
  337. package/dist/client/worker/processorOutcome.d.ts +14 -0
  338. package/dist/client/worker/processorOutcome.js +125 -0
  339. package/dist/client/worker/runtime/buffer.d.ts +8 -0
  340. package/dist/client/worker/runtime/buffer.js +50 -0
  341. package/dist/client/worker/runtime/control.d.ts +26 -0
  342. package/dist/client/worker/runtime/control.js +175 -0
  343. package/dist/client/worker/runtime/execution.d.ts +11 -0
  344. package/dist/client/worker/runtime/execution.js +123 -0
  345. package/dist/client/worker/runtime/lifecycle.d.ts +7 -0
  346. package/dist/client/worker/runtime/lifecycle.js +114 -0
  347. package/dist/client/worker/runtime/manual.d.ts +10 -0
  348. package/dist/client/worker/runtime/manual.js +137 -0
  349. package/dist/client/worker/runtime/options.d.ts +5 -0
  350. package/dist/client/worker/runtime/options.js +39 -0
  351. package/dist/client/worker/runtime/polling.d.ts +12 -0
  352. package/dist/client/worker/runtime/polling.js +123 -0
  353. package/dist/client/worker/runtime/state.d.ts +110 -0
  354. package/dist/client/worker/runtime/state.js +156 -0
  355. package/dist/client/worker/types/index.d.ts +5 -0
  356. package/dist/client/worker/types/index.js +1 -0
  357. package/dist/client/worker/types/manual.d.ts +7 -0
  358. package/dist/client/worker/types/manual.js +1 -0
  359. package/dist/client/worker/types/options.d.ts +24 -0
  360. package/dist/client/worker/types/options.js +1 -0
  361. package/dist/client/worker/types/outcome.d.ts +23 -0
  362. package/dist/client/worker/types/outcome.js +1 -0
  363. package/dist/client/worker/types/processor.d.ts +22 -0
  364. package/dist/client/worker/types/processor.js +1 -0
  365. package/dist/client/worker/types/transport.d.ts +11 -0
  366. package/dist/client/worker/types/transport.js +1 -0
  367. package/dist/client/worker/worker.d.ts +3 -160
  368. package/dist/client/worker/worker.js +3 -928
  369. package/dist/client/worker/workerRateLimiter.d.ts +5 -1
  370. package/dist/client/worker/workerRateLimiter.js +40 -20
  371. package/dist/client/worker.d.ts +1 -0
  372. package/dist/client/workflow/compensationChild.d.ts +2 -1
  373. package/dist/client/workflow/compensationChild.js +1 -1
  374. package/dist/client/workflow/compensationClaim.d.ts +11 -0
  375. package/dist/client/workflow/compensationClaim.js +30 -0
  376. package/dist/client/workflow/compensator.d.ts +7 -2
  377. package/dist/client/workflow/compensator.js +5 -11
  378. package/dist/client/workflow/recovery.js +25 -2
  379. package/dist/client/workflow/rollbackControl.js +1 -1
  380. package/dist/domain/job/constants.d.ts +12 -0
  381. package/dist/domain/job/constants.js +12 -0
  382. package/dist/domain/job/create.d.ts +2 -0
  383. package/dist/domain/job/create.js +103 -0
  384. package/dist/domain/job/ids.d.ts +5 -0
  385. package/dist/domain/job/ids.js +12 -0
  386. package/dist/domain/job/locks.d.ts +4 -0
  387. package/dist/domain/job/locks.js +23 -0
  388. package/dist/domain/job/payload.d.ts +18 -0
  389. package/dist/domain/job/payload.js +43 -0
  390. package/dist/domain/job/state.d.ts +8 -0
  391. package/dist/domain/job/state.js +51 -0
  392. package/dist/domain/job/terminal.d.ts +3 -0
  393. package/dist/domain/job/terminal.js +9 -0
  394. package/dist/domain/queue/dlqShard.d.ts +2 -0
  395. package/dist/domain/queue/dlqShard.js +34 -9
  396. package/dist/domain/queue/priorityQueue.js +3 -39
  397. package/dist/domain/queue/priorityQueueOrder.d.ts +3 -0
  398. package/dist/domain/queue/priorityQueueOrder.js +21 -0
  399. package/dist/domain/queue/shard/dependencies.d.ts +11 -0
  400. package/dist/domain/queue/shard/dependencies.js +22 -0
  401. package/dist/domain/queue/shard/dlq.d.ts +25 -0
  402. package/dist/domain/queue/shard/dlq.js +71 -0
  403. package/dist/domain/queue/shard/keys.d.ts +18 -0
  404. package/dist/domain/queue/shard/keys.js +45 -0
  405. package/dist/domain/queue/shard/lifecycle.d.ts +10 -0
  406. package/dist/domain/queue/shard/lifecycle.js +43 -0
  407. package/dist/domain/queue/shard/limits.d.ts +24 -0
  408. package/dist/domain/queue/shard/limits.js +57 -0
  409. package/dist/domain/queue/shard/metrics.d.ts +32 -0
  410. package/dist/domain/queue/shard/metrics.js +72 -0
  411. package/dist/domain/queue/shard/state.d.ts +34 -0
  412. package/dist/domain/queue/shard/state.js +80 -0
  413. package/dist/domain/queue/shard.d.ts +5 -145
  414. package/dist/domain/queue/shard.js +4 -409
  415. package/dist/domain/response/builders.d.ts +15 -0
  416. package/dist/domain/response/builders.js +39 -0
  417. package/dist/domain/types/command.d.ts +2 -555
  418. package/dist/domain/types/command.js +2 -5
  419. package/dist/domain/types/commands/base.d.ts +5 -0
  420. package/dist/domain/types/commands/base.js +1 -0
  421. package/dist/domain/types/commands/core.d.ts +106 -0
  422. package/dist/domain/types/commands/core.js +1 -0
  423. package/dist/domain/types/commands/cron.d.ts +36 -0
  424. package/dist/domain/types/commands/cron.js +1 -0
  425. package/dist/domain/types/commands/dashboard.d.ts +13 -0
  426. package/dist/domain/types/commands/dashboard.js +1 -0
  427. package/dist/domain/types/commands/dlq.d.ts +39 -0
  428. package/dist/domain/types/commands/dlq.js +1 -0
  429. package/dist/domain/types/commands/extended.d.ts +63 -0
  430. package/dist/domain/types/commands/extended.js +1 -0
  431. package/dist/domain/types/commands/index.d.ts +12 -0
  432. package/dist/domain/types/commands/index.js +12 -0
  433. package/dist/domain/types/commands/limits.d.ts +54 -0
  434. package/dist/domain/types/commands/limits.js +1 -0
  435. package/dist/domain/types/commands/management.d.ts +73 -0
  436. package/dist/domain/types/commands/management.js +1 -0
  437. package/dist/domain/types/commands/monitoring.d.ts +49 -0
  438. package/dist/domain/types/commands/monitoring.js +1 -0
  439. package/dist/domain/types/commands/protocol.d.ts +20 -0
  440. package/dist/domain/types/commands/protocol.js +1 -0
  441. package/dist/domain/types/commands/query.d.ts +46 -0
  442. package/dist/domain/types/commands/query.js +1 -0
  443. package/dist/domain/types/commands/union.d.ts +13 -0
  444. package/dist/domain/types/commands/union.js +1 -0
  445. package/dist/domain/types/commands/workers.d.ts +39 -0
  446. package/dist/domain/types/commands/workers.js +1 -0
  447. package/dist/domain/types/cron.d.ts +4 -2
  448. package/dist/domain/types/cron.js +3 -0
  449. package/dist/domain/types/dlq.d.ts +17 -0
  450. package/dist/domain/types/dlq.js +70 -14
  451. package/dist/domain/types/index.d.ts +2 -0
  452. package/dist/domain/types/index.js +1 -0
  453. package/dist/domain/types/job.d.ts +8 -269
  454. package/dist/domain/types/job.js +8 -234
  455. package/dist/domain/types/jobs/model.d.ts +152 -0
  456. package/dist/domain/types/jobs/model.js +1 -0
  457. package/dist/domain/types/metrics.d.ts +16 -0
  458. package/dist/domain/types/metrics.js +1 -0
  459. package/dist/domain/types/priorityQueue.d.ts +12 -0
  460. package/dist/domain/types/priorityQueue.js +1 -0
  461. package/dist/domain/types/protocol.d.ts +5 -0
  462. package/dist/domain/types/protocol.js +4 -0
  463. package/dist/domain/types/queue.d.ts +2 -0
  464. package/dist/domain/types/response.d.ts +3 -192
  465. package/dist/domain/types/response.js +3 -101
  466. package/dist/domain/types/responses/model.d.ts +152 -0
  467. package/dist/domain/types/responses/model.js +1 -0
  468. package/dist/domain/types/shard.d.ts +4 -0
  469. package/dist/domain/types/shard.js +1 -0
  470. package/dist/infrastructure/cloud/cloudAgent.js +6 -0
  471. package/dist/infrastructure/cloud/commandHandler.d.ts +2 -41
  472. package/dist/infrastructure/cloud/commandHandler.js +1 -1
  473. package/dist/infrastructure/cloud/commands/integrations.d.ts +2 -0
  474. package/dist/infrastructure/cloud/commands/integrations.js +31 -0
  475. package/dist/infrastructure/cloud/commands/jobMapper.d.ts +56 -0
  476. package/dist/infrastructure/cloud/commands/jobMapper.js +72 -0
  477. package/dist/infrastructure/cloud/commands/jobs.d.ts +2 -0
  478. package/dist/infrastructure/cloud/commands/jobs.js +111 -0
  479. package/dist/infrastructure/cloud/commands/queues.d.ts +2 -0
  480. package/dist/infrastructure/cloud/commands/queues.js +126 -0
  481. package/dist/infrastructure/cloud/commands.d.ts +3 -10
  482. package/dist/infrastructure/cloud/commands.js +7 -344
  483. package/dist/infrastructure/cloud/snapshot/analytics.d.ts +16 -0
  484. package/dist/infrastructure/cloud/snapshot/analytics.js +132 -0
  485. package/dist/infrastructure/cloud/snapshot/collector.d.ts +24 -0
  486. package/dist/infrastructure/cloud/snapshot/collector.js +105 -0
  487. package/dist/infrastructure/cloud/snapshot/config.d.ts +5 -0
  488. package/dist/infrastructure/cloud/snapshot/config.js +86 -0
  489. package/dist/infrastructure/cloud/snapshot/jobs.d.ts +5 -0
  490. package/dist/infrastructure/cloud/snapshot/jobs.js +148 -0
  491. package/dist/infrastructure/cloud/snapshot/stalls.d.ts +3 -0
  492. package/dist/infrastructure/cloud/snapshot/stalls.js +34 -0
  493. package/dist/infrastructure/cloud/snapshotCollector.d.ts +2 -53
  494. package/dist/infrastructure/cloud/snapshotCollector.js +5 -107
  495. package/dist/infrastructure/cloud/snapshotHelpers.d.ts +5 -45
  496. package/dist/infrastructure/cloud/snapshotHelpers.js +4 -426
  497. package/dist/infrastructure/cloud/types/collector.d.ts +54 -0
  498. package/dist/infrastructure/cloud/types/collector.js +1 -0
  499. package/dist/infrastructure/cloud/types/command.d.ts +44 -0
  500. package/dist/infrastructure/cloud/types/command.js +1 -0
  501. package/dist/infrastructure/cloud/types/config.d.ts +18 -0
  502. package/dist/infrastructure/cloud/types/config.js +1 -0
  503. package/dist/infrastructure/cloud/types/event.d.ts +14 -0
  504. package/dist/infrastructure/cloud/types/event.js +1 -0
  505. package/dist/infrastructure/cloud/types/redact.d.ts +4 -0
  506. package/dist/infrastructure/cloud/types/redact.js +1 -0
  507. package/dist/infrastructure/cloud/types/snapshot.d.ts +52 -0
  508. package/dist/infrastructure/cloud/types/snapshot.js +1 -0
  509. package/dist/infrastructure/cloud/types/snapshotCore.d.ts +125 -0
  510. package/dist/infrastructure/cloud/types/snapshotCore.js +1 -0
  511. package/dist/infrastructure/cloud/types/snapshotJobs.d.ts +124 -0
  512. package/dist/infrastructure/cloud/types/snapshotJobs.js +1 -0
  513. package/dist/infrastructure/cloud/types/snapshotTelemetry.d.ts +100 -0
  514. package/dist/infrastructure/cloud/types/snapshotTelemetry.js +1 -0
  515. package/dist/infrastructure/cloud/types.d.ts +3 -445
  516. package/dist/infrastructure/cloud/types.js +0 -4
  517. package/dist/infrastructure/persistence/batchInsert.d.ts +13 -0
  518. package/dist/infrastructure/persistence/batchInsert.js +96 -0
  519. package/dist/infrastructure/persistence/jobOptionsBlob.d.ts +18 -0
  520. package/dist/infrastructure/persistence/jobOptionsBlob.js +56 -0
  521. package/dist/infrastructure/persistence/legacyNameMigration.d.ts +5 -0
  522. package/dist/infrastructure/persistence/legacyNameMigration.js +42 -0
  523. package/dist/infrastructure/persistence/migrations.d.ts +3 -0
  524. package/dist/infrastructure/persistence/migrations.js +120 -0
  525. package/dist/infrastructure/persistence/schema.d.ts +3 -5
  526. package/dist/infrastructure/persistence/schema.js +40 -136
  527. package/dist/infrastructure/persistence/sqlite/admission.d.ts +9 -0
  528. package/dist/infrastructure/persistence/sqlite/admission.js +34 -0
  529. package/dist/infrastructure/persistence/sqlite/control.d.ts +32 -0
  530. package/dist/infrastructure/persistence/sqlite/control.js +90 -0
  531. package/dist/infrastructure/persistence/sqlite/flows.d.ts +26 -0
  532. package/dist/infrastructure/persistence/sqlite/flows.js +167 -0
  533. package/dist/infrastructure/persistence/sqlite/jobs.d.ts +23 -0
  534. package/dist/infrastructure/persistence/sqlite/jobs.js +166 -0
  535. package/dist/infrastructure/persistence/sqlite/lifecycle.d.ts +6 -0
  536. package/dist/infrastructure/persistence/sqlite/lifecycle.js +30 -0
  537. package/dist/infrastructure/persistence/sqlite/mutations.d.ts +20 -0
  538. package/dist/infrastructure/persistence/sqlite/mutations.js +149 -0
  539. package/dist/infrastructure/persistence/sqlite/queries.d.ts +23 -0
  540. package/dist/infrastructure/persistence/sqlite/queries.js +89 -0
  541. package/dist/infrastructure/persistence/sqlite/records.d.ts +24 -0
  542. package/dist/infrastructure/persistence/sqlite/records.js +115 -0
  543. package/dist/infrastructure/persistence/sqlite/state.d.ts +36 -0
  544. package/dist/infrastructure/persistence/sqlite/state.js +207 -0
  545. package/dist/infrastructure/persistence/sqlite/telemetry.d.ts +16 -0
  546. package/dist/infrastructure/persistence/sqlite/telemetry.js +126 -0
  547. package/dist/infrastructure/persistence/sqlite.d.ts +5 -280
  548. package/dist/infrastructure/persistence/sqlite.js +3 -1013
  549. package/dist/infrastructure/persistence/sqliteBatch.d.ts +4 -121
  550. package/dist/infrastructure/persistence/sqliteBatch.js +3 -422
  551. package/dist/infrastructure/persistence/sqliteSerializer.d.ts +6 -1
  552. package/dist/infrastructure/persistence/sqliteSerializer.js +33 -11
  553. package/dist/infrastructure/persistence/statements.d.ts +5 -1
  554. package/dist/infrastructure/persistence/statements.js +14 -9
  555. package/dist/infrastructure/persistence/types/admission.d.ts +8 -0
  556. package/dist/infrastructure/persistence/types/admission.js +1 -0
  557. package/dist/infrastructure/persistence/types/batch.d.ts +12 -0
  558. package/dist/infrastructure/persistence/types/batch.js +1 -0
  559. package/dist/infrastructure/persistence/types/sqlite.d.ts +17 -0
  560. package/dist/infrastructure/persistence/types/sqlite.js +1 -0
  561. package/dist/infrastructure/persistence/writeBuffer.d.ts +38 -0
  562. package/dist/infrastructure/persistence/writeBuffer.js +221 -0
  563. package/dist/infrastructure/scheduler/cron/execution.d.ts +12 -0
  564. package/dist/infrastructure/scheduler/cron/execution.js +150 -0
  565. package/dist/infrastructure/scheduler/cron/runtime.d.ts +31 -0
  566. package/dist/infrastructure/scheduler/cron/runtime.js +143 -0
  567. package/dist/infrastructure/scheduler/cronScheduler.d.ts +4 -117
  568. package/dist/infrastructure/scheduler/cronScheduler.js +3 -436
  569. package/dist/infrastructure/scheduler/types/cronScheduler.d.ts +16 -0
  570. package/dist/infrastructure/scheduler/types/cronScheduler.js +1 -0
  571. package/dist/infrastructure/server/bootstrap.js +3 -0
  572. package/dist/infrastructure/server/handler-routes/control.d.ts +8 -0
  573. package/dist/infrastructure/server/handler-routes/control.js +82 -0
  574. package/dist/infrastructure/server/handler-routes/jobs.d.ts +6 -0
  575. package/dist/infrastructure/server/handler-routes/jobs.js +110 -0
  576. package/dist/infrastructure/server/handler-routes/monitoring.d.ts +5 -0
  577. package/dist/infrastructure/server/handler-routes/monitoring.js +65 -0
  578. package/dist/infrastructure/server/handlerRoutes.d.ts +3 -26
  579. package/dist/infrastructure/server/handlerRoutes.js +3 -270
  580. package/dist/infrastructure/server/handlers/advanced/configNumbers.d.ts +2 -0
  581. package/dist/infrastructure/server/handlers/advanced/configNumbers.js +26 -0
  582. package/dist/infrastructure/server/handlers/advanced/dependencies.d.ts +15 -0
  583. package/dist/infrastructure/server/handlers/advanced/dependencies.js +38 -0
  584. package/dist/infrastructure/server/handlers/advanced/jobs.d.ts +33 -0
  585. package/dist/infrastructure/server/handlers/advanced/jobs.js +136 -0
  586. package/dist/infrastructure/server/handlers/advanced/queue.d.ts +42 -0
  587. package/dist/infrastructure/server/handlers/advanced/queue.js +111 -0
  588. package/dist/infrastructure/server/handlers/advanced.d.ts +3 -121
  589. package/dist/infrastructure/server/handlers/advanced.js +3 -336
  590. package/dist/infrastructure/server/handlers/core.d.ts +1 -4
  591. package/dist/infrastructure/server/handlers/core.js +37 -20
  592. package/dist/infrastructure/server/handlers/cron.js +9 -1
  593. package/dist/infrastructure/server/handlers/flow.js +6 -1
  594. package/dist/infrastructure/server/handlers/introspection.js +1 -1
  595. package/dist/infrastructure/server/handlers/management.d.ts +8 -0
  596. package/dist/infrastructure/server/handlers/management.js +30 -0
  597. package/dist/infrastructure/server/handlers/monitoring/health.d.ts +13 -0
  598. package/dist/infrastructure/server/handlers/monitoring/health.js +61 -0
  599. package/dist/infrastructure/server/handlers/monitoring/operations.d.ts +8 -0
  600. package/dist/infrastructure/server/handlers/monitoring/operations.js +28 -0
  601. package/dist/infrastructure/server/handlers/monitoring/webhooks.d.ts +7 -0
  602. package/dist/infrastructure/server/handlers/monitoring/webhooks.js +56 -0
  603. package/dist/infrastructure/server/handlers/monitoring/workers.d.ts +6 -0
  604. package/dist/infrastructure/server/handlers/monitoring/workers.js +57 -0
  605. package/dist/infrastructure/server/handlers/monitoring.d.ts +4 -30
  606. package/dist/infrastructure/server/handlers/monitoring.js +4 -222
  607. package/dist/infrastructure/server/handlers/pushBatchValidation.d.ts +1 -1
  608. package/dist/infrastructure/server/handlers/pushBatchValidation.js +7 -0
  609. package/dist/infrastructure/server/handlers/query.js +12 -3
  610. package/dist/infrastructure/server/http-routes/jobAdvanced.d.ts +2 -0
  611. package/dist/infrastructure/server/http-routes/jobAdvanced.js +106 -0
  612. package/dist/infrastructure/server/http-routes/jobManagement.d.ts +2 -0
  613. package/dist/infrastructure/server/http-routes/jobManagement.js +74 -0
  614. package/dist/infrastructure/server/http-routes/queueJobs.d.ts +2 -0
  615. package/dist/infrastructure/server/http-routes/queueJobs.js +108 -0
  616. package/dist/infrastructure/server/httpRouteJobs.d.ts +1 -8
  617. package/dist/infrastructure/server/httpRouteJobs.js +33 -222
  618. package/dist/infrastructure/server/httpRouteQueues.d.ts +1 -6
  619. package/dist/infrastructure/server/httpRouteQueues.js +51 -217
  620. package/dist/infrastructure/server/httpRouteResources.js +1 -0
  621. package/dist/infrastructure/server/protocol/commands.d.ts +8 -0
  622. package/dist/infrastructure/server/protocol/commands.js +31 -0
  623. package/dist/infrastructure/server/protocol/frameParser.d.ts +16 -0
  624. package/dist/infrastructure/server/protocol/frameParser.js +65 -0
  625. package/dist/infrastructure/server/protocol/lineBuffer.d.ts +6 -0
  626. package/dist/infrastructure/server/protocol/lineBuffer.js +21 -0
  627. package/dist/infrastructure/server/protocol/validation.d.ts +9 -0
  628. package/dist/infrastructure/server/protocol/validation.js +75 -0
  629. package/dist/infrastructure/server/protocol.d.ts +5 -77
  630. package/dist/infrastructure/server/protocol.js +4 -265
  631. package/dist/infrastructure/server/rateLimiter.js +1 -0
  632. package/dist/infrastructure/server/socketWriteQueue.d.ts +1 -1
  633. package/dist/infrastructure/server/socketWriteQueue.js +8 -5
  634. package/dist/infrastructure/server/sse/constants.d.ts +5 -0
  635. package/dist/infrastructure/server/sse/constants.js +5 -0
  636. package/dist/infrastructure/server/sse/eventBuffer.d.ts +3 -0
  637. package/dist/infrastructure/server/sse/eventBuffer.js +21 -0
  638. package/dist/infrastructure/server/sseHandler.d.ts +2 -6
  639. package/dist/infrastructure/server/sseHandler.js +20 -96
  640. package/dist/infrastructure/server/tcp/clientRelease.d.ts +2 -0
  641. package/dist/infrastructure/server/tcp/clientRelease.js +18 -0
  642. package/dist/infrastructure/server/tcp/connections.d.ts +24 -0
  643. package/dist/infrastructure/server/tcp/connections.js +162 -0
  644. package/dist/infrastructure/server/tcp/constants.d.ts +3 -0
  645. package/dist/infrastructure/server/tcp/constants.js +3 -0
  646. package/dist/infrastructure/server/tcp/eventSubscriptions.d.ts +10 -0
  647. package/dist/infrastructure/server/tcp/eventSubscriptions.js +17 -0
  648. package/dist/infrastructure/server/tcp/responses.d.ts +3 -0
  649. package/dist/infrastructure/server/tcp/responses.js +8 -0
  650. package/dist/infrastructure/server/tcp.d.ts +10 -68
  651. package/dist/infrastructure/server/tcp.js +47 -256
  652. package/dist/infrastructure/server/types/protocol.d.ts +4 -0
  653. package/dist/infrastructure/server/types/protocol.js +1 -0
  654. package/dist/infrastructure/server/types/sse.d.ts +11 -0
  655. package/dist/infrastructure/server/types/sse.js +1 -0
  656. package/dist/infrastructure/server/types/tcpServer.d.ts +25 -0
  657. package/dist/infrastructure/server/types/tcpServer.js +1 -0
  658. package/dist/infrastructure/server/types/ws.d.ts +6 -0
  659. package/dist/infrastructure/server/types/ws.js +1 -0
  660. package/dist/infrastructure/server/ws/constants.d.ts +6 -0
  661. package/dist/infrastructure/server/ws/constants.js +130 -0
  662. package/dist/infrastructure/server/ws/snapshots.d.ts +4 -0
  663. package/dist/infrastructure/server/ws/snapshots.js +52 -0
  664. package/dist/infrastructure/server/ws/subscriptions.d.ts +10 -0
  665. package/dist/infrastructure/server/ws/subscriptions.js +39 -0
  666. package/dist/infrastructure/server/wsHandler.d.ts +2 -10
  667. package/dist/infrastructure/server/wsHandler.js +12 -237
  668. package/dist/mcp/adapter.d.ts +5 -403
  669. package/dist/mcp/adapter.js +6 -778
  670. package/dist/mcp/backend/embedded/base.d.ts +7 -0
  671. package/dist/mcp/backend/embedded/base.js +15 -0
  672. package/dist/mcp/backend/embedded/index.d.ts +14 -0
  673. package/dist/mcp/backend/embedded/index.js +22 -0
  674. package/dist/mcp/backend/embedded/jobs.d.ts +44 -0
  675. package/dist/mcp/backend/embedded/jobs.js +98 -0
  676. package/dist/mcp/backend/embedded/queues.d.ts +27 -0
  677. package/dist/mcp/backend/embedded/queues.js +84 -0
  678. package/dist/mcp/backend/embedded/services.d.ts +29 -0
  679. package/dist/mcp/backend/embedded/services.js +107 -0
  680. package/dist/mcp/backend/serializers.d.ts +7 -0
  681. package/dist/mcp/backend/serializers.js +32 -0
  682. package/dist/mcp/backend/tcp/base.d.ts +19 -0
  683. package/dist/mcp/backend/tcp/base.js +54 -0
  684. package/dist/mcp/backend/tcp/index.d.ts +14 -0
  685. package/dist/mcp/backend/tcp/index.js +20 -0
  686. package/dist/mcp/backend/tcp/jobs.d.ts +44 -0
  687. package/dist/mcp/backend/tcp/jobs.js +122 -0
  688. package/dist/mcp/backend/tcp/queues.d.ts +27 -0
  689. package/dist/mcp/backend/tcp/queues.js +89 -0
  690. package/dist/mcp/backend/tcp/services.d.ts +30 -0
  691. package/dist/mcp/backend/tcp/services.js +161 -0
  692. package/dist/mcp/types/adapter.d.ts +176 -0
  693. package/dist/mcp/types/adapter.js +1 -0
  694. package/dist/shared/asyncLock.d.ts +13 -0
  695. package/dist/shared/asyncLock.js +65 -0
  696. package/dist/shared/lock.d.ts +10 -72
  697. package/dist/shared/lock.js +7 -231
  698. package/dist/shared/lockError.d.ts +3 -0
  699. package/dist/shared/lockError.js +6 -0
  700. package/dist/shared/lockTimeout.d.ts +2 -0
  701. package/dist/shared/lockTimeout.js +2 -0
  702. package/dist/shared/rwLock.d.ts +22 -0
  703. package/dist/shared/rwLock.js +124 -0
  704. package/dist/shared/serialization.js +1 -0
  705. package/dist/shared/skipList.d.ts +0 -5
  706. package/dist/shared/skipList.js +10 -57
  707. package/dist/shared/skipListNodes.d.ts +6 -0
  708. package/dist/shared/skipListNodes.js +43 -0
  709. package/dist/shared/types/lock.d.ts +7 -0
  710. package/dist/shared/types/lock.js +1 -0
  711. package/dist/shared/types/skipList.d.ts +4 -0
  712. package/dist/shared/types/skipList.js +1 -0
  713. package/package.json +2 -1
  714. package/dist/application/types.d.ts +0 -148
  715. package/dist/client/sandboxed/types.d.ts +0 -79
  716. package/dist/client/sandboxed/types.js +0 -5
  717. package/dist/client/worker/types.d.ts +0 -50
  718. /package/dist/client/queue/{queueTypes.js → types/contexts.js} +0 -0
@@ -1,929 +1,4 @@
1
- /**
2
- * Worker
3
- * BullMQ-style worker for job processing
4
- */
5
- import { EventEmitter } from 'events';
6
- import { hostname } from 'os';
7
- import { getSharedManager } from '../manager';
8
- import { TcpConnectionPool } from '../tcpPool';
9
- import { jobId } from '../../domain/types/job';
10
- import { FORCE_EMBEDDED, WORKER_CONSTANTS } from './types';
11
- import { AckBatcher } from './ackBatcher';
12
- import { parseJobFromResponse } from './jobParser';
13
- import { processJob } from './processor';
14
- import { WorkerRateLimiter } from './workerRateLimiter';
15
- import { GroupConcurrencyLimiter } from './groupConcurrency';
16
- import { startHeartbeat, sendHeartbeat } from './workerHeartbeat';
17
- import { pullEmbedded, pullTcp } from './workerPull';
18
- import { resolveToken } from '../resolveToken';
19
- /** Resolve WorkerOptions into ExtendedWorkerOptions with defaults */
20
- function resolveWorkerOptions(opts, embedded) {
21
- return {
22
- concurrency: opts.concurrency ?? 1,
23
- autorun: opts.autorun ?? true,
24
- heartbeatInterval: opts.heartbeatInterval ?? 10000,
25
- batchSize: Math.min(opts.batchSize ?? 10, 1000),
26
- pollTimeout: Math.min(opts.pollTimeout ?? 0, WORKER_CONSTANTS.MAX_POLL_TIMEOUT),
27
- embedded,
28
- useLocks: opts.useLocks ?? true,
29
- skipLockRenewal: opts.skipLockRenewal ?? false,
30
- skipStalledCheck: opts.skipStalledCheck ?? false,
31
- drainDelay: opts.drainDelay ?? 50,
32
- lockDuration: opts.lockDuration ?? 30000,
33
- maxStalledCount: opts.maxStalledCount ?? 1,
34
- removeOnComplete: opts.removeOnComplete,
35
- removeOnFail: opts.removeOnFail,
36
- };
37
- }
38
- /** Create TCP connection pool from options */
39
- function createTcpPool(opts, concurrency) {
40
- const connOpts = opts.connection ?? {};
41
- const poolSize = connOpts.poolSize ?? Math.min(concurrency, 8);
42
- const token = resolveToken(connOpts.token);
43
- return new TcpConnectionPool({
44
- host: connOpts.host ?? 'localhost',
45
- port: connOpts.port ?? 6789,
46
- token,
47
- tls: connOpts.tls,
48
- poolSize,
49
- pingInterval: connOpts.pingInterval,
50
- commandTimeout: connOpts.commandTimeout,
51
- maxCommandTimeouts: connOpts.maxCommandTimeouts,
52
- pipelining: connOpts.pipelining,
53
- maxInFlight: connOpts.maxInFlight,
54
- });
55
- }
56
- /**
57
- * Worker class for processing jobs
58
- */
59
- export class Worker extends EventEmitter {
60
- name;
61
- /**
62
- * Server-side queue key. Equals `name` unless `prefixKey` is set, in which
63
- * case it is `prefixKey + name`. All broker pulls/registrations route
64
- * through this key so a Worker only sees jobs from its own namespace.
65
- */
66
- queueKey;
67
- opts;
68
- processor;
69
- embedded;
70
- tcp;
71
- tcpPool;
72
- ackBatcher;
73
- rateLimiter;
74
- groupLimiter;
75
- running = false;
76
- paused = false;
77
- _closing = false;
78
- // Set when a force close is requested — allows close(true) to pre-empt an
79
- // in-progress graceful close(false) by breaking out of its drain loop.
80
- _forceClose = false;
81
- _closingPromise = null;
82
- closed = false;
83
- activeJobs = 0;
84
- pollTimer = null;
85
- consecutiveErrors = 0;
86
- // Heartbeat tracking with lock tokens (BullMQ-style ownership)
87
- // Track ALL pulled jobs (both active and buffered) for heartbeat
88
- activeJobIds = new Set();
89
- pulledJobIds = new Set(); // All pulled jobs (for heartbeat)
90
- jobTokens = new Map(); // jobId -> lockToken
91
- cancelledJobs = new Set(); // Jobs marked for cancellation
92
- heartbeatTimer = null;
93
- // Worker registration tracking
94
- workerHeartbeatTimer = null;
95
- processedCount = 0;
96
- failedCount = 0;
97
- startedAt;
98
- registered = false;
99
- // Unique worker ID for lock ownership
100
- workerId;
101
- // Job buffer for batch pulls (with tokens)
102
- pendingJobs = [];
103
- pendingJobsHead = 0;
104
- processingScheduled = false; // Prevent multiple setImmediate calls
105
- // Slots reserved by in-flight doPullBatch() calls (Issue #98). Subtracted from
106
- // free slots so overlapping pulls see each other and do not over-lease.
107
- pendingPull = 0;
108
- // Drained event tracking
109
- lastDrainedEmit = 0;
110
- // Stalled event subscription (BullMQ v5 compatible)
111
- stalledUnsubscribe = null;
112
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
- on(event, listener) {
114
- return super.on(event, listener);
115
- }
116
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
- once(event, listener) {
118
- return super.once(event, listener);
119
- }
120
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
121
- off(event, listener) {
122
- return super.off(event, listener);
123
- }
124
- constructor(name, processor, opts = {}) {
125
- super();
126
- this.name = name;
127
- this.queueKey = (opts.prefixKey ?? '') + name;
128
- this.processor = processor;
129
- this.embedded = opts.embedded ?? FORCE_EMBEDDED;
130
- this.startedAt = Date.now();
131
- this.workerId = `worker-${this.queueKey}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
132
- this.opts = resolveWorkerOptions(opts, this.embedded);
133
- this.rateLimiter = new WorkerRateLimiter(opts.limiter?.groupKey ? null : (opts.limiter ?? null));
134
- this.groupLimiter = GroupConcurrencyLimiter.fromOptions(opts.limiter);
135
- this.ackBatcher = new AckBatcher({
136
- batchSize: opts.batchSize ?? 10,
137
- interval: WORKER_CONSTANTS.DEFAULT_ACK_INTERVAL,
138
- embedded: this.embedded,
139
- });
140
- if (this.embedded) {
141
- getSharedManager(opts.dataPath);
142
- this.tcp = null;
143
- this.tcpPool = null;
144
- }
145
- else {
146
- this.tcpPool = createTcpPool(opts, this.opts.concurrency);
147
- this.tcp = this.tcpPool;
148
- this.ackBatcher.setTcp(this.tcp);
149
- // The server drops worker registration when the registering connection
150
- // closes, and each pooled reconnect gets a fresh server clientId. Re-send
151
- // RegisterWorker on reconnect so the worker stays visible in
152
- // WorkerManager (ListWorkers / getForQueue / skipIfNoWorker) while it
153
- // keeps consuming jobs. Only acts once we were actually registered.
154
- this.tcpPool.onReconnect(() => {
155
- if (this.closed || this._closing || !this.registered)
156
- return;
157
- this.registered = false;
158
- this.registerWithServer();
159
- });
160
- }
161
- if (this.opts.autorun)
162
- this.run();
163
- }
164
- /** Start processing */
165
- run() {
166
- if (this.running || this.closed)
167
- return;
168
- this.running = true;
169
- this.paused = false;
170
- this._closing = false;
171
- this._forceClose = false;
172
- this._closingPromise = null;
173
- // Defer the 'ready' emit so listeners attached synchronously after
174
- // construction (e.g. `new Worker(...).on('ready', ...)`) still receive it.
175
- // run() is called from the constructor when autorun is true (the default),
176
- // at which point chained or post-construction listeners haven't been
177
- // registered yet. See issue #76.
178
- queueMicrotask(() => {
179
- if (!this.closed)
180
- this.emit('ready');
181
- });
182
- // Subscribe to stalled events in embedded mode (BullMQ v5)
183
- if (this.embedded && !this.stalledUnsubscribe && !this.opts.skipStalledCheck) {
184
- this.subscribeToStalledEvents();
185
- }
186
- // Register the worker in the selected broker runtime.
187
- if (this.embedded && !this.registered) {
188
- getSharedManager().registerWorker(this.queueKey, [this.queueKey], this.opts.concurrency, {
189
- workerId: this.workerId,
190
- hostname: hostname(),
191
- pid: process.pid,
192
- startedAt: this.startedAt,
193
- });
194
- this.registered = true;
195
- }
196
- else if (this.tcp && !this.registered) {
197
- this.registerWithServer();
198
- }
199
- if (this.opts.heartbeatInterval > 0 && !this.opts.skipLockRenewal) {
200
- if (this.embedded) {
201
- this.heartbeatTimer = setInterval(() => {
202
- const manager = getSharedManager();
203
- for (const id of this.pulledJobIds) {
204
- manager.jobHeartbeat(jobId(id));
205
- }
206
- }, this.opts.heartbeatInterval);
207
- }
208
- else {
209
- const deps = this.getHeartbeatDeps();
210
- this.heartbeatTimer = startHeartbeat(deps, this.opts.heartbeatInterval);
211
- }
212
- }
213
- if (this.opts.heartbeatInterval > 0)
214
- this.startWorkerHeartbeat();
215
- this.poll();
216
- }
217
- /** Subscribe to stalled events from QueueManager (BullMQ v5 compatible) */
218
- subscribeToStalledEvents() {
219
- if (!this.embedded)
220
- return;
221
- const manager = getSharedManager();
222
- this.stalledUnsubscribe = manager.subscribe((event) => {
223
- // Events carry the prefixed server-side queue key, so we must compare
224
- // against `queueKey` (not the logical `name`) to scope correctly.
225
- if (event.queue !== this.queueKey)
226
- return;
227
- if (event.eventType === "stalled" /* EventType.Stalled */) {
228
- this.emit('stalled', event.jobId, 'active');
229
- }
230
- });
231
- }
232
- /** Pause processing */
233
- pause() {
234
- if (!this.running)
235
- return;
236
- this.running = false;
237
- this.paused = true;
238
- if (this.pollTimer) {
239
- clearTimeout(this.pollTimer);
240
- this.pollTimer = null;
241
- }
242
- }
243
- /** Resume processing */
244
- resume() {
245
- if (this.closed)
246
- return;
247
- this.paused = false;
248
- this.run();
249
- }
250
- isRunning() {
251
- return this.running;
252
- }
253
- isPaused() {
254
- return this.paused && !this.closed;
255
- }
256
- isClosed() {
257
- return this.closed;
258
- }
259
- /** Get current concurrency */
260
- get concurrency() {
261
- return this.opts.concurrency;
262
- }
263
- /** Set concurrency at runtime (BullMQ v5 compatible) */
264
- set concurrency(val) {
265
- const clamped = Math.max(1, val);
266
- const prev = this.opts.concurrency;
267
- this.opts.concurrency = clamped;
268
- if (clamped > prev && this.running && !this._closing) {
269
- this.poll();
270
- }
271
- }
272
- /** Promise that resolves when close() finishes (BullMQ v5 compatible) */
273
- get closing() {
274
- return this._closingPromise;
275
- }
276
- async waitUntilReady() {
277
- if (this.embedded)
278
- return;
279
- if (this.tcpPool) {
280
- await this.tcpPool.send({ cmd: 'Ping' });
281
- }
282
- }
283
- cancelJob(jobId, reason) {
284
- if (this.activeJobIds.has(jobId)) {
285
- this.cancelledJobs.add(jobId);
286
- this.emit('cancelled', { jobId, reason: reason ?? 'Job cancelled by worker' });
287
- return true;
288
- }
289
- return false;
290
- }
291
- cancelAllJobs(reason) {
292
- for (const jobId of this.activeJobIds) {
293
- this.cancelledJobs.add(jobId);
294
- this.emit('cancelled', { jobId, reason: reason ?? 'All jobs cancelled' });
295
- }
296
- }
297
- isJobCancelled(jobId) {
298
- return this.cancelledJobs.has(jobId);
299
- }
300
- // ============ Rate Limiter (delegated) ============
301
- getRateLimiterInfo() {
302
- return this.rateLimiter.getRateLimiterInfo();
303
- }
304
- rateLimit(expireTimeMs) {
305
- this.rateLimiter.rateLimit(expireTimeMs);
306
- }
307
- isRateLimited() {
308
- return this.rateLimiter.isRateLimited();
309
- }
310
- // ============ BullMQ v5 Compatibility ============
311
- async startStalledCheckTimer() {
312
- // No-op for API compatibility - stall detection is automatic
313
- }
314
- async delay(milliseconds = 0, abortController) {
315
- if (milliseconds <= 0)
316
- return;
317
- return new Promise((resolve, reject) => {
318
- const timeout = setTimeout(resolve, milliseconds);
319
- if (abortController) {
320
- abortController.signal.addEventListener('abort', () => {
321
- clearTimeout(timeout);
322
- reject(new Error('Delay aborted'));
323
- });
324
- }
325
- });
326
- }
327
- // ============ Manual Job Control ============
328
- async getNextJob(token, _opts) {
329
- if (this.closed)
330
- return undefined;
331
- if (this.embedded) {
332
- const manager = getSharedManager();
333
- if (this.opts.useLocks) {
334
- // Forward the configured lock duration; without it pullWithLock falls
335
- // back to the server default and a custom `lockDuration` is silently
336
- // ignored on this manual-acquire path (same class as #111). The main
337
- // run-loop path (workerPull.ts) already forwards it.
338
- const { job, token: lockToken } = await manager.pullWithLock(this.queueKey, this.workerId, 0, this.opts.lockDuration);
339
- if (job && lockToken) {
340
- const jobIdStr = String(job.id);
341
- this.pulledJobIds.add(jobIdStr);
342
- this.jobTokens.set(jobIdStr, lockToken);
343
- }
344
- return job ?? undefined;
345
- }
346
- const job = await manager.pull(this.queueKey, 0);
347
- if (job) {
348
- this.pulledJobIds.add(String(job.id));
349
- }
350
- return job ?? undefined;
351
- }
352
- // TCP mode
353
- if (!this.tcp)
354
- return undefined;
355
- const cmd = {
356
- cmd: 'PULL',
357
- queue: this.queueKey,
358
- timeout: 0,
359
- };
360
- if (this.opts.useLocks) {
361
- cmd.owner = this.workerId;
362
- // Forward the configured lock TTL (mirrors workerPull.ts); otherwise the
363
- // server applies its 30s default and a custom lockDuration is dropped.
364
- if (this.opts.lockDuration !== undefined)
365
- cmd.lockTtl = this.opts.lockDuration;
366
- if (token)
367
- cmd.token = token;
368
- }
369
- const response = await this.tcp.send(cmd);
370
- if (!response.ok || !response.job)
371
- return undefined;
372
- const job = parseJobFromResponse(response.job, this.queueKey);
373
- const jobIdStr = String(job.id);
374
- this.pulledJobIds.add(jobIdStr);
375
- if (this.opts.useLocks && response.token) {
376
- this.jobTokens.set(jobIdStr, response.token);
377
- }
378
- return job;
379
- }
380
- async processJobManually(job, token, fetchNextCallback) {
381
- if (this.closed)
382
- return undefined;
383
- const jobIdStr = String(job.id);
384
- this.activeJobs++;
385
- this.activeJobIds.add(jobIdStr);
386
- this.pulledJobIds.add(jobIdStr);
387
- if (this.opts.useLocks && token) {
388
- this.jobTokens.set(jobIdStr, token);
389
- }
390
- try {
391
- await processJob(job, {
392
- name: this.queueKey,
393
- processor: this.processor,
394
- embedded: this.embedded,
395
- tcp: this.tcp,
396
- ackBatcher: this.ackBatcher,
397
- emitter: this,
398
- token: this.opts.useLocks ? token : undefined,
399
- });
400
- if (fetchNextCallback) {
401
- return await fetchNextCallback();
402
- }
403
- }
404
- finally {
405
- this.activeJobs--;
406
- this.activeJobIds.delete(jobIdStr);
407
- this.pulledJobIds.delete(jobIdStr);
408
- this.cancelledJobs.delete(jobIdStr);
409
- if (this.opts.useLocks) {
410
- this.jobTokens.delete(jobIdStr);
411
- }
412
- this.rateLimiter.recordJobForLimiter();
413
- }
414
- }
415
- async extendJobLocks(jobIds, tokens, duration) {
416
- if (this.closed || jobIds.length === 0)
417
- return 0;
418
- if (jobIds.length !== tokens.length) {
419
- throw new Error('jobIds and tokens arrays must have the same length');
420
- }
421
- if (this.embedded) {
422
- const manager = getSharedManager();
423
- let extended = 0;
424
- for (let i = 0; i < jobIds.length; i++) {
425
- const success = await manager.extendLock(jobIds[i], tokens[i], duration);
426
- if (success)
427
- extended++;
428
- }
429
- return extended;
430
- }
431
- if (!this.tcp)
432
- return 0;
433
- const response = await this.tcp.send({
434
- cmd: 'ExtendLocks',
435
- ids: jobIds,
436
- tokens,
437
- // Protocol expects a per-id `durations` array, and the handler returns
438
- // `count` (not `extended`). Sending `duration`/reading `extended` made
439
- // batch lock renewal silently keep the old TTL.
440
- durations: jobIds.map(() => duration),
441
- });
442
- const extended = response.count;
443
- return extended ?? 0;
444
- }
445
- // ============ Lifecycle ============
446
- async close(force = false) {
447
- if (this.closed)
448
- return;
449
- // A force close must be able to pre-empt an in-progress graceful close:
450
- // the graceful drain only waits on genuinely in-flight jobs, but a caller
451
- // asking to force-close wants to stop waiting now. Flip the force flag so
452
- // the running _doClose's drain loop exits, and return the same promise.
453
- if (this._closingPromise) {
454
- if (force)
455
- this._forceClose = true;
456
- return this._closingPromise;
457
- }
458
- this._forceClose = force;
459
- this._closingPromise = this._doClose(force);
460
- return this._closingPromise;
461
- }
462
- async _doClose(force) {
463
- this._closing = true;
464
- this.running = false;
465
- this.paused = false;
466
- if (this.pollTimer) {
467
- clearTimeout(this.pollTimer);
468
- this.pollTimer = null;
469
- }
470
- if (this.heartbeatTimer) {
471
- clearInterval(this.heartbeatTimer);
472
- this.heartbeatTimer = null;
473
- }
474
- if (this.workerHeartbeatTimer) {
475
- clearInterval(this.workerHeartbeatTimer);
476
- this.workerHeartbeatTimer = null;
477
- }
478
- // Release buffered pulled-but-unstarted jobs back to the queue. During
479
- // _closing every code path that would advance the buffer (poll/tryProcess/
480
- // the startJob().finally re-poll) early-returns, so a buffered job is never
481
- // started — yet it holds a server-side lock and sits in `active` state.
482
- // Without this, a graceful drain that waited on the buffer would hang
483
- // forever (e.g. group-limited jobs buffered behind a max:1 limiter). We
484
- // requeue them (Active -> Waiting) so they are re-pullable and not lost.
485
- await this.releaseBufferedJobs();
486
- if (!force) {
487
- // Wait only on genuinely in-flight jobs. The buffer was released above,
488
- // so it must NOT be part of the drain condition. A concurrent force
489
- // close (this._forceClose) breaks out immediately.
490
- while (this.activeJobs > 0 && !this._forceClose) {
491
- await Bun.sleep(50);
492
- }
493
- }
494
- await this.ackBatcher.flush();
495
- await this.ackBatcher.waitForInFlight();
496
- this.ackBatcher.stop();
497
- // Unregister before closing the transport/runtime.
498
- if (this.registered) {
499
- if (this.embedded) {
500
- getSharedManager().unregisterWorker(this.workerId);
501
- }
502
- else if (this.tcp) {
503
- try {
504
- await this.tcp.send({ cmd: 'UnregisterWorker', workerId: this.workerId });
505
- }
506
- catch {
507
- // Best-effort unregister — server will cleanup via stale timeout
508
- }
509
- }
510
- this.registered = false;
511
- }
512
- await Bun.sleep(100);
513
- if (this.stalledUnsubscribe) {
514
- this.stalledUnsubscribe();
515
- this.stalledUnsubscribe = null;
516
- }
517
- this.activeJobIds.clear();
518
- this.pulledJobIds.clear();
519
- this.jobTokens.clear();
520
- this.cancelledJobs.clear();
521
- this.pendingJobs = [];
522
- this.pendingJobsHead = 0;
523
- if (this.groupLimiter)
524
- this.groupLimiter.clear();
525
- if (this.tcpPool)
526
- this.tcpPool.close();
527
- this.closed = true;
528
- this._closing = false;
529
- this.emit('closed');
530
- }
531
- /**
532
- * Release all buffered (pulled-but-unstarted) jobs back to the queue on close.
533
- * These jobs are `active` server-side holding a lock; moving them back to
534
- * `waiting` makes them re-pullable so nothing is lost, and removes them from
535
- * the close drain (which would otherwise hang on a buffer that can never be
536
- * advanced while `_closing` is set). Best-effort: a job that can't be
537
- * released (e.g. already completed/stall-retried) is simply dropped from the
538
- * local buffer — its server-side lock will expire and requeue it.
539
- */
540
- async releaseBufferedJobs() {
541
- const buffered = this.pendingJobs.slice(this.pendingJobsHead);
542
- this.pendingJobs = [];
543
- this.pendingJobsHead = 0;
544
- if (buffered.length === 0)
545
- return;
546
- for (const { job, token } of buffered) {
547
- const id = String(job.id);
548
- try {
549
- if (this.embedded) {
550
- const manager = getSharedManager();
551
- await manager.moveActiveToWait(jobId(id));
552
- // moveActiveToWait re-queues the job (active -> waiting); release the
553
- // lock token we still hold so it is fully owner-free and re-pullable.
554
- if (this.opts.useLocks)
555
- manager.releaseLock(jobId(id), token ?? undefined);
556
- }
557
- else if (this.tcp) {
558
- await this.tcp.send({ cmd: 'MoveToWait', id });
559
- }
560
- }
561
- catch {
562
- // Best-effort: lock expiration will requeue anything we couldn't release.
563
- }
564
- finally {
565
- this.pulledJobIds.delete(id);
566
- this.jobTokens.delete(id);
567
- }
568
- }
569
- }
570
- // ============ Processing Pipeline ============
571
- poll() {
572
- if (!this.running || this._closing)
573
- return;
574
- if (this.activeJobs >= this.opts.concurrency) {
575
- this.pollTimer = setTimeout(() => {
576
- this.poll();
577
- }, 10);
578
- return;
579
- }
580
- // Check rate limiter
581
- if (!this.rateLimiter.canProcessWithinLimit()) {
582
- const waitTime = this.rateLimiter.getTimeUntilNextSlot();
583
- this.pollTimer = setTimeout(() => {
584
- this.poll();
585
- }, Math.max(waitTime, 10));
586
- return;
587
- }
588
- void this.tryProcess();
589
- }
590
- async tryProcess() {
591
- if (!this.running || this._closing)
592
- return;
593
- try {
594
- let item = this.getNextEligibleJob();
595
- if (!item) {
596
- const items = await this.doPullBatch();
597
- // Re-check state after async operation (can be modified during await)
598
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
599
- if (!this.running || this._closing)
600
- return;
601
- if (items.length > 0) {
602
- this.registerPulledJobs(items);
603
- // Add all items to buffer, then find eligible one
604
- if (this.pendingJobsHead >= this.pendingJobs.length) {
605
- this.pendingJobs = items;
606
- this.pendingJobsHead = 0;
607
- }
608
- else {
609
- this.pendingJobs = this.pendingJobs.slice(this.pendingJobsHead).concat(items);
610
- this.pendingJobsHead = 0;
611
- }
612
- item = this.getNextEligibleJob();
613
- }
614
- }
615
- if (item) {
616
- // Issue #96: re-check the concurrency gate before starting. poll()
617
- // checked it, but `await doPullBatch()` above — or a setImmediate path
618
- // that bypasses poll() — may have filled the slots since. This check is
619
- // atomic with startJob()'s activeJobs++ (no await between here and the
620
- // increment), so it cannot overshoot. If full, requeue the job (we still
621
- // own it via pulledJobIds/jobTokens) and let a freed slot pick it up.
622
- if (this.activeJobs >= this.opts.concurrency) {
623
- this.requeueItem(item);
624
- this.pollTimer = setTimeout(() => {
625
- this.poll();
626
- }, 10);
627
- return;
628
- }
629
- this.consecutiveErrors = 0;
630
- this.startJob(item.job, item.token);
631
- }
632
- else {
633
- // Check if we have buffered jobs but all are group-limited
634
- const hasBuffered = this.pendingJobsHead < this.pendingJobs.length;
635
- if (hasBuffered && this.groupLimiter) {
636
- // Retry shortly - a running job may finish and free a group slot
637
- this.pollTimer = setTimeout(() => {
638
- this.poll();
639
- }, 10);
640
- return;
641
- }
642
- const now = Date.now();
643
- if (now - this.lastDrainedEmit > 1000) {
644
- this.lastDrainedEmit = now;
645
- this.emit('drained');
646
- }
647
- const waitTime = this.opts.pollTimeout > 0 ? 10 : this.opts.drainDelay;
648
- this.pollTimer = setTimeout(() => {
649
- this.poll();
650
- }, waitTime);
651
- }
652
- }
653
- catch (err) {
654
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
655
- if (!this.running)
656
- return;
657
- this.handlePullError(err);
658
- }
659
- }
660
- registerPulledJobs(items) {
661
- for (const pulledItem of items) {
662
- const jobIdStr = String(pulledItem.job.id);
663
- this.pulledJobIds.add(jobIdStr);
664
- if (this.opts.useLocks && pulledItem.token) {
665
- this.jobTokens.set(jobIdStr, pulledItem.token);
666
- }
667
- }
668
- // Renew the just-pulled locks immediately (fire-and-forget). With a pooled
669
- // client (poolSize > 1), the PULL and subsequent heartbeats travel on
670
- // different connections; the server only releases an in-flight job on
671
- // connection drop if its lock was never renewed (renewalCount === 0). The
672
- // periodic heartbeat timer does not fire until one interval later, leaving a
673
- // window where a dropped pulling-socket would re-dispatch a job the worker
674
- // is actively running. An immediate renew closes that window. Only needed
675
- // for multi-connection lock-based workers (poolSize 1 keeps pull+heartbeat
676
- // on the same socket, so there is nothing to protect against).
677
- if (this.opts.useLocks && items.length > 0 && this.tcpPool && this.tcpPool.getPoolSize() > 1) {
678
- void sendHeartbeat(this.getHeartbeatDeps());
679
- }
680
- }
681
- getBufferedJob() {
682
- if (this.pendingJobsHead >= this.pendingJobs.length)
683
- return null;
684
- const item = this.pendingJobs[this.pendingJobsHead++];
685
- if (this.pendingJobsHead > 500 && this.pendingJobsHead >= this.pendingJobs.length / 2) {
686
- this.pendingJobs = this.pendingJobs.slice(this.pendingJobsHead);
687
- this.pendingJobsHead = 0;
688
- }
689
- return item;
690
- }
691
- /** Put an item back at the front of the pending buffer (Issue #96). */
692
- requeueItem(item) {
693
- if (this.pendingJobsHead > 0) {
694
- this.pendingJobs[--this.pendingJobsHead] = item;
695
- }
696
- else {
697
- this.pendingJobs.unshift(item);
698
- }
699
- }
700
- /**
701
- * Get the next buffered job eligible for processing.
702
- * When group concurrency is enabled, skips jobs whose group is at capacity
703
- * and leaves them in the buffer for later processing.
704
- */
705
- getNextEligibleJob() {
706
- if (this.pendingJobsHead >= this.pendingJobs.length)
707
- return null;
708
- // No group limiter - just return the next buffered job
709
- if (!this.groupLimiter) {
710
- return this.getBufferedJob();
711
- }
712
- // Scan buffer for a job whose group has capacity
713
- const start = this.pendingJobsHead;
714
- const end = this.pendingJobs.length;
715
- for (let i = start; i < end; i++) {
716
- const item = this.pendingJobs[i];
717
- if (this.groupLimiter.canProcess(item.job)) {
718
- // Remove this item from the buffer by swapping with the head
719
- this.pendingJobs[i] = this.pendingJobs[this.pendingJobsHead];
720
- this.pendingJobsHead++;
721
- if (this.pendingJobsHead > 500 && this.pendingJobsHead >= this.pendingJobs.length / 2) {
722
- this.pendingJobs = this.pendingJobs.slice(this.pendingJobsHead);
723
- this.pendingJobsHead = 0;
724
- }
725
- return item;
726
- }
727
- }
728
- return null;
729
- }
730
- async doPullBatch() {
731
- // Issue #98: cap the LEASED count (running + buffered + in-flight pulls) at
732
- // `concurrency`, not just the running count. The old `concurrency - activeJobs`
733
- // was read once and the pull leases jobs on the broker across an await, so:
734
- // 1. several concurrent finally->poll->tryProcess runs each read the same
735
- // stale count and each pull a full batch, and
736
- // 2. a job just pulled by one run sits in `pendingJobs` (leased, counted by
737
- // the heartbeat) but not yet in `activeJobs`, so an overlapping pull does
738
- // not see it.
739
- // Both leak: with concurrency=3 the worker ends up holding 5-6 jobs leased.
740
- // `pulledJobIds.size` is the true leased count (active + buffered; a job is
741
- // removed only on completion), and `pendingPull` reserves slots for pulls
742
- // still in flight whose jobs are not yet registered.
743
- //
744
- // Exception — group pull-ahead: when a group limiter is set AND the buffer is
745
- // non-empty here (this branch is reached only after getNextEligibleJob() found
746
- // nothing runnable, so those buffered jobs are group-blocked), the worker must
747
- // pull ahead to discover jobs from other, runnable groups — otherwise it would
748
- // wedge on a buffer full of one blocked group. In that case the blocked
749
- // buffered jobs are not counted (only the running ones are). This preserves the
750
- // existing group behavior; the reported over-pull (no group limiter) always
751
- // uses the strict leased cap.
752
- const groupBlockedBuffer = this.groupLimiter !== null && this.pendingJobsHead < this.pendingJobs.length;
753
- const leased = groupBlockedBuffer ? this.activeJobs : this.pulledJobIds.size;
754
- const slots = this.opts.concurrency - leased - this.pendingPull;
755
- const batchSize = Math.min(this.opts.batchSize, slots, 1000);
756
- if (batchSize <= 0)
757
- return [];
758
- const config = this.getPullConfig();
759
- this.pendingPull += batchSize;
760
- try {
761
- return this.embedded
762
- ? await pullEmbedded(config, batchSize)
763
- : await pullTcp(config, this.tcp, batchSize, this._closing);
764
- }
765
- finally {
766
- // Release the reservation. The pulled jobs are now registered/buffered (or
767
- // the pull failed); either way the reservation has served its purpose for
768
- // the duration of the in-flight pull.
769
- this.pendingPull -= batchSize;
770
- }
771
- }
772
- startJob(job, token) {
773
- const jobIdStr = String(job.id);
774
- // Dedup: skip if this job is already being processed (Issue #33)
775
- // This happens when stall detection retries a job while the worker
776
- // is still processing it, and the worker's other concurrency slot
777
- // pulls the retried job from the queue.
778
- if (this.activeJobIds.has(jobIdStr)) {
779
- return;
780
- }
781
- this.activeJobs++;
782
- this.activeJobIds.add(jobIdStr);
783
- // Apply worker-level removeOnComplete/removeOnFail defaults to the job
784
- this.applyRemoveDefaults(job);
785
- // Track group concurrency
786
- if (this.groupLimiter) {
787
- this.groupLimiter.increment(job);
788
- }
789
- if (this.opts.useLocks && token && !this.jobTokens.has(jobIdStr)) {
790
- this.jobTokens.set(jobIdStr, token);
791
- }
792
- this.pulledJobIds.add(jobIdStr);
793
- const tokenForProcess = this.opts.useLocks ? token : undefined;
794
- void processJob(job, {
795
- name: this.queueKey,
796
- processor: this.processor,
797
- embedded: this.embedded,
798
- tcp: this.tcp,
799
- ackBatcher: this.ackBatcher,
800
- emitter: this,
801
- token: tokenForProcess,
802
- onOutcome: (ok) => {
803
- if (ok)
804
- this.processedCount++;
805
- else
806
- this.failedCount++;
807
- },
808
- }).finally(() => {
809
- this.activeJobs--;
810
- this.activeJobIds.delete(jobIdStr);
811
- this.pulledJobIds.delete(jobIdStr);
812
- this.cancelledJobs.delete(jobIdStr);
813
- if (this.opts.useLocks) {
814
- this.jobTokens.delete(jobIdStr);
815
- }
816
- // Release group concurrency slot
817
- if (this.groupLimiter) {
818
- this.groupLimiter.decrement(job);
819
- }
820
- this.rateLimiter.recordJobForLimiter();
821
- if (this.running && !this._closing)
822
- this.poll();
823
- });
824
- if (this.activeJobs < this.opts.concurrency && !this._closing && !this.processingScheduled) {
825
- this.processingScheduled = true;
826
- setImmediate(() => {
827
- this.processingScheduled = false;
828
- void this.tryProcess();
829
- });
830
- }
831
- }
832
- handlePullError(err) {
833
- this.consecutiveErrors++;
834
- const error = err instanceof Error ? err : new Error(String(err));
835
- this.emit('error', Object.assign(error, {
836
- queue: this.name,
837
- consecutiveErrors: this.consecutiveErrors,
838
- context: 'pull',
839
- }));
840
- const backoffMs = Math.min(WORKER_CONSTANTS.BASE_BACKOFF_MS * Math.pow(2, this.consecutiveErrors - 1), WORKER_CONSTANTS.MAX_BACKOFF_MS);
841
- this.pollTimer = setTimeout(() => {
842
- this.poll();
843
- }, backoffMs);
844
- }
845
- // ============ Private Helpers ============
846
- /** Register this worker with the server (TCP only, fire-and-forget) */
847
- registerWithServer() {
848
- if (!this.tcp || this.registered)
849
- return;
850
- void this.tcp
851
- .send({
852
- cmd: 'RegisterWorker',
853
- name: this.queueKey,
854
- queues: [this.queueKey],
855
- concurrency: this.opts.concurrency,
856
- workerId: this.workerId,
857
- hostname: hostname(),
858
- pid: process.pid,
859
- startedAt: this.startedAt,
860
- })
861
- .then(() => {
862
- this.registered = true;
863
- })
864
- .catch((err) => {
865
- const error = err instanceof Error ? err : new Error(String(err));
866
- this.emit('error', Object.assign(error, { context: 'worker-register' }));
867
- });
868
- }
869
- /** Start periodic worker-level heartbeat (separate from job heartbeat). */
870
- startWorkerHeartbeat() {
871
- if (this.workerHeartbeatTimer)
872
- return;
873
- this.workerHeartbeatTimer = setInterval(() => {
874
- if (!this.registered)
875
- return;
876
- if (this.embedded) {
877
- getSharedManager().workerManager.heartbeat(this.workerId, {
878
- activeJobs: this.activeJobs,
879
- processed: this.processedCount,
880
- failed: this.failedCount,
881
- });
882
- return;
883
- }
884
- if (!this.tcp)
885
- return;
886
- void this.tcp
887
- .send({
888
- cmd: 'Heartbeat',
889
- id: this.workerId,
890
- activeJobs: this.activeJobs,
891
- processed: this.processedCount,
892
- failed: this.failedCount,
893
- })
894
- .catch((err) => {
895
- const error = err instanceof Error ? err : new Error(String(err));
896
- this.emit('error', Object.assign(error, { context: 'worker-heartbeat' }));
897
- });
898
- }, this.opts.heartbeatInterval);
899
- }
900
- getHeartbeatDeps() {
901
- return {
902
- pulledJobIds: this.pulledJobIds,
903
- jobTokens: this.jobTokens,
904
- tcp: this.tcp,
905
- useLocks: this.opts.useLocks,
906
- emitter: this,
907
- };
908
- }
909
- getPullConfig() {
910
- return {
911
- name: this.queueKey,
912
- workerId: this.workerId,
913
- useLocks: this.opts.useLocks,
914
- pollTimeout: this.opts.pollTimeout,
915
- lockDuration: this.opts.lockDuration,
916
- };
917
- }
918
- /** Apply worker-level removeOnComplete/removeOnFail defaults to a job */
919
- applyRemoveDefaults(job) {
920
- if (this.opts.removeOnComplete !== undefined && !job.removeOnComplete) {
921
- const val = this.opts.removeOnComplete;
922
- job.removeOnComplete = val === true;
923
- }
924
- if (this.opts.removeOnFail !== undefined && !job.removeOnFail) {
925
- const val = this.opts.removeOnFail;
926
- job.removeOnFail = val === true;
927
- }
928
- }
1
+ /** Public Worker façade. Runtime implementation lives in worker/runtime/. */
2
+ import { WorkerExecution } from './runtime/execution';
3
+ export class Worker extends WorkerExecution {
929
4
  }