bunqueue 2.8.59 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/README.md +109 -77
  2. package/dist/application/background/dlq.js +2 -0
  3. package/dist/application/contextFactory.js +5 -0
  4. package/dist/application/dlqManager.d.ts +11 -1
  5. package/dist/application/dlqManager.js +48 -10
  6. package/dist/application/dlqRetry.js +59 -38
  7. package/dist/application/eventsManager.d.ts +1 -1
  8. package/dist/application/eventsManager.js +30 -26
  9. package/dist/application/lockManager.js +1 -1
  10. package/dist/application/operations/jobManagement.d.ts +4 -0
  11. package/dist/application/operations/jobMoveOperations.js +9 -4
  12. package/dist/application/postgres-queue-manager/batchSnapshot.d.ts +16 -0
  13. package/dist/application/postgres-queue-manager/batchSnapshot.js +17 -0
  14. package/dist/application/postgres-queue-manager/cloud.d.ts +30 -0
  15. package/dist/application/postgres-queue-manager/cloud.js +55 -0
  16. package/dist/application/postgres-queue-manager/config.d.ts +5 -0
  17. package/dist/application/postgres-queue-manager/config.js +1 -0
  18. package/dist/application/postgres-queue-manager/control.d.ts +26 -0
  19. package/dist/application/postgres-queue-manager/control.js +186 -0
  20. package/dist/application/postgres-queue-manager/deferredWrites.d.ts +13 -0
  21. package/dist/application/postgres-queue-manager/deferredWrites.js +60 -0
  22. package/dist/application/postgres-queue-manager/delivery.d.ts +19 -0
  23. package/dist/application/postgres-queue-manager/delivery.js +80 -0
  24. package/dist/application/postgres-queue-manager/lease.d.ts +13 -0
  25. package/dist/application/postgres-queue-manager/lease.js +88 -0
  26. package/dist/application/postgres-queue-manager/lifetimeMetrics.d.ts +32 -0
  27. package/dist/application/postgres-queue-manager/lifetimeMetrics.js +53 -0
  28. package/dist/application/postgres-queue-manager/maintenance.d.ts +14 -0
  29. package/dist/application/postgres-queue-manager/maintenance.js +100 -0
  30. package/dist/application/postgres-queue-manager/operationGate.d.ts +26 -0
  31. package/dist/application/postgres-queue-manager/operationGate.js +96 -0
  32. package/dist/application/postgres-queue-manager/operations.d.ts +25 -0
  33. package/dist/application/postgres-queue-manager/operations.js +194 -0
  34. package/dist/application/postgres-queue-manager/projectionRefreshes.d.ts +43 -0
  35. package/dist/application/postgres-queue-manager/projectionRefreshes.js +170 -0
  36. package/dist/application/postgres-queue-manager/queries.d.ts +142 -0
  37. package/dist/application/postgres-queue-manager/queries.js +231 -0
  38. package/dist/application/postgres-queue-manager/relationships.d.ts +10 -0
  39. package/dist/application/postgres-queue-manager/relationships.js +45 -0
  40. package/dist/application/postgres-queue-manager/services.d.ts +31 -0
  41. package/dist/application/postgres-queue-manager/services.js +149 -0
  42. package/dist/application/postgres-queue-manager/snapshot.d.ts +51 -0
  43. package/dist/application/postgres-queue-manager/snapshot.js +236 -0
  44. package/dist/application/postgres-queue-manager/snapshotViews.d.ts +15 -0
  45. package/dist/application/postgres-queue-manager/snapshotViews.js +100 -0
  46. package/dist/application/postgres-queue-manager/startupEventBuffer.d.ts +12 -0
  47. package/dist/application/postgres-queue-manager/startupEventBuffer.js +36 -0
  48. package/dist/application/postgres-queue-manager/state.d.ts +47 -0
  49. package/dist/application/postgres-queue-manager/state.js +273 -0
  50. package/dist/application/postgres-queue-manager/terminalDelivery.d.ts +20 -0
  51. package/dist/application/postgres-queue-manager/terminalDelivery.js +100 -0
  52. package/dist/application/postgresQueueManager.d.ts +2 -0
  53. package/dist/application/postgresQueueManager.js +1 -0
  54. package/dist/application/queue-manager/ack.js +1 -1
  55. package/dist/application/queue-manager/delivery.js +1 -1
  56. package/dist/application/queue-manager/flow-failures.js +4 -0
  57. package/dist/application/queue-manager/limits.d.ts +2 -0
  58. package/dist/application/queue-manager/limits.js +4 -0
  59. package/dist/application/queue-manager/observability.js +15 -3
  60. package/dist/application/queue-manager/queries.d.ts +7 -0
  61. package/dist/application/queue-manager/queries.js +9 -0
  62. package/dist/application/queue-manager/services.d.ts +1 -1
  63. package/dist/application/queue-manager/services.js +4 -2
  64. package/dist/application/queue-manager/state.js +16 -1
  65. package/dist/application/statsManager.d.ts +1 -1
  66. package/dist/application/statsManager.js +1 -1
  67. package/dist/cli/commands/server.js +1 -1
  68. package/dist/client/events.js +2 -2
  69. package/dist/client/flow.js +0 -1
  70. package/dist/client/forwarder.d.ts +6 -4
  71. package/dist/client/forwarder.js +5 -3
  72. package/dist/client/queue/dlq.d.ts +2 -0
  73. package/dist/client/queue/dlq.js +14 -0
  74. package/dist/client/queue/dlqOps.d.ts +2 -0
  75. package/dist/client/queue/dlqOps.js +4 -0
  76. package/dist/client/queue/helpers.js +2 -0
  77. package/dist/client/queue/operations/add/single.js +1 -1
  78. package/dist/client/queue/runtime/configuration.d.ts +4 -0
  79. package/dist/client/queue/runtime/configuration.js +8 -0
  80. package/dist/client/sandboxed/runtime/state.js +2 -2
  81. package/dist/client/tcp/connection.d.ts +1 -1
  82. package/dist/client/tcp/connection.js +1 -1
  83. package/dist/client/tcp/runtime/state.js +2 -2
  84. package/dist/client/types/metrics.d.ts +1 -1
  85. package/dist/client/worker/runtime/control.js +0 -1
  86. package/dist/client/worker/runtime/execution.js +3 -8
  87. package/dist/client/worker/runtime/lifecycle.js +0 -1
  88. package/dist/client/worker/runtime/polling.d.ts +1 -0
  89. package/dist/client/worker/runtime/polling.js +9 -0
  90. package/dist/client/worker/runtime/state.js +3 -3
  91. package/dist/client/workflow/compensationChild.d.ts +2 -0
  92. package/dist/client/workflow/compensationChild.js +3 -1
  93. package/dist/client/workflow/compensationPass.d.ts +1 -0
  94. package/dist/client/workflow/compensationPass.js +18 -2
  95. package/dist/client/workflow/compensator.d.ts +2 -1
  96. package/dist/client/workflow/compensator.js +11 -3
  97. package/dist/client/workflow/engine.js +1 -1
  98. package/dist/client/workflow/executionFence.d.ts +15 -0
  99. package/dist/client/workflow/executionFence.js +29 -0
  100. package/dist/client/workflow/executor.d.ts +5 -11
  101. package/dist/client/workflow/executor.js +48 -47
  102. package/dist/client/workflow/executorLifecycle.d.ts +1 -0
  103. package/dist/client/workflow/executorLifecycle.js +41 -10
  104. package/dist/client/workflow/executorNodes.d.ts +1 -0
  105. package/dist/client/workflow/executorNodes.js +45 -16
  106. package/dist/client/workflow/executorQueue.d.ts +9 -0
  107. package/dist/client/workflow/executorQueue.js +15 -0
  108. package/dist/client/workflow/forEachRunner.d.ts +4 -0
  109. package/dist/client/workflow/forEachRunner.js +70 -0
  110. package/dist/client/workflow/loops.d.ts +4 -5
  111. package/dist/client/workflow/loops.js +27 -93
  112. package/dist/client/workflow/mapRunner.d.ts +1 -1
  113. package/dist/client/workflow/mapRunner.js +11 -2
  114. package/dist/client/workflow/recovery.d.ts +1 -0
  115. package/dist/client/workflow/recovery.js +24 -18
  116. package/dist/client/workflow/rollbackControl.d.ts +1 -0
  117. package/dist/client/workflow/rollbackControl.js +5 -2
  118. package/dist/client/workflow/runner.d.ts +3 -1
  119. package/dist/client/workflow/runner.js +26 -3
  120. package/dist/client/workflow/stepTypes.js +1 -1
  121. package/dist/client/workflow/subWorkflowRunner.d.ts +1 -0
  122. package/dist/client/workflow/subWorkflowRunner.js +7 -0
  123. package/dist/client/workflow/waitFor.d.ts +4 -0
  124. package/dist/client/workflow/waitFor.js +23 -11
  125. package/dist/client/workflow/workflowDecisions.d.ts +1 -1
  126. package/dist/client/workflow/workflowDecisions.js +3 -1
  127. package/dist/config/resolve.d.ts +14 -0
  128. package/dist/config/resolve.js +50 -5
  129. package/dist/config/types.d.ts +18 -0
  130. package/dist/domain/queue/dlqShard.d.ts +2 -0
  131. package/dist/domain/queue/dlqShard.js +16 -0
  132. package/dist/domain/queue/shard/dlq.d.ts +1 -0
  133. package/dist/domain/queue/shard/dlq.js +3 -0
  134. package/dist/domain/types/commands/dlq.d.ts +5 -0
  135. package/dist/domain/types/commands/union.d.ts +1 -1
  136. package/dist/domain/types/cron.d.ts +5 -0
  137. package/dist/domain/types/cron.js +14 -3
  138. package/dist/domain/types/dlq.d.ts +1 -1
  139. package/dist/domain/types/dlq.js +1 -2
  140. package/dist/domain/types/jobs/model.d.ts +1 -1
  141. package/dist/infrastructure/cloud/commandHandler.js +5 -3
  142. package/dist/infrastructure/cloud/commands/integrations.js +11 -11
  143. package/dist/infrastructure/cloud/commands/jobs.js +48 -40
  144. package/dist/infrastructure/cloud/commands/queues.js +61 -75
  145. package/dist/infrastructure/cloud/queueAdapter/local.d.ts +41 -0
  146. package/dist/infrastructure/cloud/queueAdapter/local.js +187 -0
  147. package/dist/infrastructure/cloud/queueAdapter/postgres.d.ts +42 -0
  148. package/dist/infrastructure/cloud/queueAdapter/postgres.js +188 -0
  149. package/dist/infrastructure/cloud/queueAdapter/registry.d.ts +4 -0
  150. package/dist/infrastructure/cloud/queueAdapter/registry.js +15 -0
  151. package/dist/infrastructure/cloud/queueAdapter/types.d.ts +87 -0
  152. package/dist/infrastructure/cloud/queueAdapter/types.js +1 -0
  153. package/dist/infrastructure/cloud/snapshot/analytics.d.ts +2 -0
  154. package/dist/infrastructure/cloud/snapshot/analytics.js +7 -0
  155. package/dist/infrastructure/cloud/snapshot/collector.d.ts +4 -0
  156. package/dist/infrastructure/cloud/snapshot/collector.js +39 -1
  157. package/dist/infrastructure/cloud/snapshot/config.d.ts +3 -0
  158. package/dist/infrastructure/cloud/snapshot/config.js +43 -0
  159. package/dist/infrastructure/cloud/snapshot/jobs.d.ts +3 -0
  160. package/dist/infrastructure/cloud/snapshot/jobs.js +32 -1
  161. package/dist/infrastructure/cloud/snapshotCollector.js +20 -35
  162. package/dist/infrastructure/cloud/snapshotHelpers.d.ts +3 -3
  163. package/dist/infrastructure/cloud/snapshotHelpers.js +3 -3
  164. package/dist/infrastructure/cloud/statsRefresh.js +2 -1
  165. package/dist/infrastructure/cloud/types/command.d.ts +2 -2
  166. package/dist/infrastructure/persistence/postgres/admission.d.ts +18 -0
  167. package/dist/infrastructure/persistence/postgres/admission.js +193 -0
  168. package/dist/infrastructure/persistence/postgres/admissionParent.d.ts +5 -0
  169. package/dist/infrastructure/persistence/postgres/admissionParent.js +35 -0
  170. package/dist/infrastructure/persistence/postgres/admissionResult.d.ts +9 -0
  171. package/dist/infrastructure/persistence/postgres/admissionResult.js +1 -0
  172. package/dist/infrastructure/persistence/postgres/admissionStore.d.ts +12 -0
  173. package/dist/infrastructure/persistence/postgres/admissionStore.js +101 -0
  174. package/dist/infrastructure/persistence/postgres/advisoryLocks.d.ts +2 -0
  175. package/dist/infrastructure/persistence/postgres/advisoryLocks.js +13 -0
  176. package/dist/infrastructure/persistence/postgres/batchAdmission.d.ts +11 -0
  177. package/dist/infrastructure/persistence/postgres/batchAdmission.js +110 -0
  178. package/dist/infrastructure/persistence/postgres/batchCompletion.d.ts +4 -0
  179. package/dist/infrastructure/persistence/postgres/batchCompletion.js +174 -0
  180. package/dist/infrastructure/persistence/postgres/batchEvents.d.ts +14 -0
  181. package/dist/infrastructure/persistence/postgres/batchEvents.js +72 -0
  182. package/dist/infrastructure/persistence/postgres/brokerSessions.d.ts +14 -0
  183. package/dist/infrastructure/persistence/postgres/brokerSessions.js +94 -0
  184. package/dist/infrastructure/persistence/postgres/claimBatch.d.ts +11 -0
  185. package/dist/infrastructure/persistence/postgres/claimBatch.js +56 -0
  186. package/dist/infrastructure/persistence/postgres/claimSelection.d.ts +4 -0
  187. package/dist/infrastructure/persistence/postgres/claimSelection.js +198 -0
  188. package/dist/infrastructure/persistence/postgres/claims.d.ts +3 -0
  189. package/dist/infrastructure/persistence/postgres/claims.js +137 -0
  190. package/dist/infrastructure/persistence/postgres/cloudReadModel.d.ts +26 -0
  191. package/dist/infrastructure/persistence/postgres/cloudReadModel.js +123 -0
  192. package/dist/infrastructure/persistence/postgres/codec.d.ts +30 -0
  193. package/dist/infrastructure/persistence/postgres/codec.js +82 -0
  194. package/dist/infrastructure/persistence/postgres/completionEvents.d.ts +11 -0
  195. package/dist/infrastructure/persistence/postgres/completionEvents.js +21 -0
  196. package/dist/infrastructure/persistence/postgres/completionLifecycle.d.ts +11 -0
  197. package/dist/infrastructure/persistence/postgres/completionLifecycle.js +145 -0
  198. package/dist/infrastructure/persistence/postgres/completionOutcome.d.ts +4 -0
  199. package/dist/infrastructure/persistence/postgres/completionOutcome.js +112 -0
  200. package/dist/infrastructure/persistence/postgres/completionQueries.d.ts +10 -0
  201. package/dist/infrastructure/persistence/postgres/completionQueries.js +87 -0
  202. package/dist/infrastructure/persistence/postgres/connection.d.ts +3 -0
  203. package/dist/infrastructure/persistence/postgres/connection.js +15 -0
  204. package/dist/infrastructure/persistence/postgres/context.d.ts +28 -0
  205. package/dist/infrastructure/persistence/postgres/context.js +74 -0
  206. package/dist/infrastructure/persistence/postgres/control.d.ts +23 -0
  207. package/dist/infrastructure/persistence/postgres/control.js +105 -0
  208. package/dist/infrastructure/persistence/postgres/crons.d.ts +18 -0
  209. package/dist/infrastructure/persistence/postgres/crons.js +205 -0
  210. package/dist/infrastructure/persistence/postgres/deduplication.d.ts +9 -0
  211. package/dist/infrastructure/persistence/postgres/deduplication.js +47 -0
  212. package/dist/infrastructure/persistence/postgres/dependencyDestruction.d.ts +14 -0
  213. package/dist/infrastructure/persistence/postgres/dependencyDestruction.js +74 -0
  214. package/dist/infrastructure/persistence/postgres/dependencyPromotion.d.ts +29 -0
  215. package/dist/infrastructure/persistence/postgres/dependencyPromotion.js +212 -0
  216. package/dist/infrastructure/persistence/postgres/destructiveMutations.d.ts +4 -0
  217. package/dist/infrastructure/persistence/postgres/destructiveMutations.js +111 -0
  218. package/dist/infrastructure/persistence/postgres/dlqLifecycle.d.ts +13 -0
  219. package/dist/infrastructure/persistence/postgres/dlqLifecycle.js +184 -0
  220. package/dist/infrastructure/persistence/postgres/dlqMaintenance.d.ts +6 -0
  221. package/dist/infrastructure/persistence/postgres/dlqMaintenance.js +36 -0
  222. package/dist/infrastructure/persistence/postgres/dlqRetryPlan.d.ts +21 -0
  223. package/dist/infrastructure/persistence/postgres/dlqRetryPlan.js +92 -0
  224. package/dist/infrastructure/persistence/postgres/eventCommitGc.d.ts +27 -0
  225. package/dist/infrastructure/persistence/postgres/eventCommitGc.js +62 -0
  226. package/dist/infrastructure/persistence/postgres/eventJournal.d.ts +18 -0
  227. package/dist/infrastructure/persistence/postgres/eventJournal.js +76 -0
  228. package/dist/infrastructure/persistence/postgres/eventJournalSchema.d.ts +5 -0
  229. package/dist/infrastructure/persistence/postgres/eventJournalSchema.js +253 -0
  230. package/dist/infrastructure/persistence/postgres/eventPruneWatermarks.d.ts +24 -0
  231. package/dist/infrastructure/persistence/postgres/eventPruneWatermarks.js +111 -0
  232. package/dist/infrastructure/persistence/postgres/eventRetention.d.ts +18 -0
  233. package/dist/infrastructure/persistence/postgres/eventRetention.js +76 -0
  234. package/dist/infrastructure/persistence/postgres/events.d.ts +45 -0
  235. package/dist/infrastructure/persistence/postgres/events.js +249 -0
  236. package/dist/infrastructure/persistence/postgres/expiry.d.ts +3 -0
  237. package/dist/infrastructure/persistence/postgres/expiry.js +74 -0
  238. package/dist/infrastructure/persistence/postgres/flowFailures.d.ts +17 -0
  239. package/dist/infrastructure/persistence/postgres/flowFailures.js +199 -0
  240. package/dist/infrastructure/persistence/postgres/jobData.d.ts +3 -0
  241. package/dist/infrastructure/persistence/postgres/jobData.js +32 -0
  242. package/dist/infrastructure/persistence/postgres/leaseRelease.d.ts +9 -0
  243. package/dist/infrastructure/persistence/postgres/leaseRelease.js +120 -0
  244. package/dist/infrastructure/persistence/postgres/leaseRenewal.d.ts +4 -0
  245. package/dist/infrastructure/persistence/postgres/leaseRenewal.js +35 -0
  246. package/dist/infrastructure/persistence/postgres/lifetimeMetrics.d.ts +15 -0
  247. package/dist/infrastructure/persistence/postgres/lifetimeMetrics.js +46 -0
  248. package/dist/infrastructure/persistence/postgres/lifetimeMetricsFinalizer.d.ts +4 -0
  249. package/dist/infrastructure/persistence/postgres/lifetimeMetricsFinalizer.js +13 -0
  250. package/dist/infrastructure/persistence/postgres/logs.d.ts +6 -0
  251. package/dist/infrastructure/persistence/postgres/logs.js +70 -0
  252. package/dist/infrastructure/persistence/postgres/maintenance.d.ts +6 -0
  253. package/dist/infrastructure/persistence/postgres/maintenance.js +138 -0
  254. package/dist/infrastructure/persistence/postgres/maintenanceFlights.d.ts +14 -0
  255. package/dist/infrastructure/persistence/postgres/maintenanceFlights.js +66 -0
  256. package/dist/infrastructure/persistence/postgres/metricWrites.d.ts +9 -0
  257. package/dist/infrastructure/persistence/postgres/metricWrites.js +94 -0
  258. package/dist/infrastructure/persistence/postgres/mutations.d.ts +9 -0
  259. package/dist/infrastructure/persistence/postgres/mutations.js +171 -0
  260. package/dist/infrastructure/persistence/postgres/outcomes.d.ts +4 -0
  261. package/dist/infrastructure/persistence/postgres/outcomes.js +194 -0
  262. package/dist/infrastructure/persistence/postgres/policies.d.ts +11 -0
  263. package/dist/infrastructure/persistence/postgres/policies.js +18 -0
  264. package/dist/infrastructure/persistence/postgres/postCommitMaintenance.d.ts +17 -0
  265. package/dist/infrastructure/persistence/postgres/postCommitMaintenance.js +117 -0
  266. package/dist/infrastructure/persistence/postgres/promotion.d.ts +3 -0
  267. package/dist/infrastructure/persistence/postgres/promotion.js +43 -0
  268. package/dist/infrastructure/persistence/postgres/queries.d.ts +22 -0
  269. package/dist/infrastructure/persistence/postgres/queries.js +152 -0
  270. package/dist/infrastructure/persistence/postgres/queueDestruction.d.ts +3 -0
  271. package/dist/infrastructure/persistence/postgres/queueDestruction.js +154 -0
  272. package/dist/infrastructure/persistence/postgres/queueLifecycle.d.ts +10 -0
  273. package/dist/infrastructure/persistence/postgres/queueLifecycle.js +60 -0
  274. package/dist/infrastructure/persistence/postgres/rateLimit.d.ts +6 -0
  275. package/dist/infrastructure/persistence/postgres/rateLimit.js +10 -0
  276. package/dist/infrastructure/persistence/postgres/readModels.d.ts +32 -0
  277. package/dist/infrastructure/persistence/postgres/readModels.js +72 -0
  278. package/dist/infrastructure/persistence/postgres/recovery.d.ts +3 -0
  279. package/dist/infrastructure/persistence/postgres/recovery.js +178 -0
  280. package/dist/infrastructure/persistence/postgres/relationships.d.ts +9 -0
  281. package/dist/infrastructure/persistence/postgres/relationships.js +201 -0
  282. package/dist/infrastructure/persistence/postgres/removeUnprocessedChildren.d.ts +4 -0
  283. package/dist/infrastructure/persistence/postgres/removeUnprocessedChildren.js +241 -0
  284. package/dist/infrastructure/persistence/postgres/repeatMutations.d.ts +5 -0
  285. package/dist/infrastructure/persistence/postgres/repeatMutations.js +37 -0
  286. package/dist/infrastructure/persistence/postgres/runtime.d.ts +46 -0
  287. package/dist/infrastructure/persistence/postgres/runtime.js +236 -0
  288. package/dist/infrastructure/persistence/postgres/runtimeConfig.d.ts +21 -0
  289. package/dist/infrastructure/persistence/postgres/runtimeConfig.js +39 -0
  290. package/dist/infrastructure/persistence/postgres/schema.d.ts +4 -0
  291. package/dist/infrastructure/persistence/postgres/schema.js +257 -0
  292. package/dist/infrastructure/persistence/postgres/schemaInitialization.d.ts +3 -0
  293. package/dist/infrastructure/persistence/postgres/schemaInitialization.js +221 -0
  294. package/dist/infrastructure/persistence/postgres/serialAdmission.d.ts +6 -0
  295. package/dist/infrastructure/persistence/postgres/serialAdmission.js +96 -0
  296. package/dist/infrastructure/persistence/postgres/snapshotBudget.d.ts +3 -0
  297. package/dist/infrastructure/persistence/postgres/snapshotBudget.js +83 -0
  298. package/dist/infrastructure/persistence/postgres/storageHealth.d.ts +10 -0
  299. package/dist/infrastructure/persistence/postgres/storageHealth.js +29 -0
  300. package/dist/infrastructure/persistence/postgres/store.d.ts +90 -0
  301. package/dist/infrastructure/persistence/postgres/store.js +136 -0
  302. package/dist/infrastructure/persistence/postgres/telemetry.d.ts +6 -0
  303. package/dist/infrastructure/persistence/postgres/telemetry.js +88 -0
  304. package/dist/infrastructure/persistence/postgres/terminal.d.ts +8 -0
  305. package/dist/infrastructure/persistence/postgres/terminal.js +137 -0
  306. package/dist/infrastructure/persistence/postgres/transactionRetry.d.ts +6 -0
  307. package/dist/infrastructure/persistence/postgres/transactionRetry.js +42 -0
  308. package/dist/infrastructure/persistence/postgres/types.d.ts +175 -0
  309. package/dist/infrastructure/persistence/postgres/types.js +1 -0
  310. package/dist/infrastructure/persistence/postgres/workers.d.ts +15 -0
  311. package/dist/infrastructure/persistence/postgres/workers.js +126 -0
  312. package/dist/infrastructure/persistence/postgres.d.ts +2 -0
  313. package/dist/infrastructure/persistence/postgres.js +1 -0
  314. package/dist/infrastructure/persistence/sqlite/jobs.js +2 -0
  315. package/dist/infrastructure/persistence/sqlite.d.ts +1 -1
  316. package/dist/infrastructure/scheduler/cron/persisted.d.ts +5 -0
  317. package/dist/infrastructure/scheduler/cron/persisted.js +27 -0
  318. package/dist/infrastructure/scheduler/cron/runtime.js +5 -10
  319. package/dist/infrastructure/scheduler/cron/validation.d.ts +3 -0
  320. package/dist/infrastructure/scheduler/cron/validation.js +11 -0
  321. package/dist/infrastructure/scheduler/cronParser.d.ts +1 -1
  322. package/dist/infrastructure/scheduler/cronParser.js +144 -11
  323. package/dist/infrastructure/server/bootstrap.d.ts +2 -3
  324. package/dist/infrastructure/server/bootstrap.js +33 -59
  325. package/dist/infrastructure/server/errors.d.ts +4 -0
  326. package/dist/infrastructure/server/errors.js +54 -0
  327. package/dist/infrastructure/server/handler-routes/control.d.ts +5 -5
  328. package/dist/infrastructure/server/handler-routes/control.js +3 -1
  329. package/dist/infrastructure/server/handler-routes/jobs.js +0 -3
  330. package/dist/infrastructure/server/handler-routes/monitoring.d.ts +2 -2
  331. package/dist/infrastructure/server/handler.js +9 -11
  332. package/dist/infrastructure/server/handlerRoutes.d.ts +2 -2
  333. package/dist/infrastructure/server/handlerRoutes.js +2 -2
  334. package/dist/infrastructure/server/handlers/advanced/dependencies.js +7 -6
  335. package/dist/infrastructure/server/handlers/advanced/jobs.js +19 -6
  336. package/dist/infrastructure/server/handlers/advanced/queue.d.ts +9 -9
  337. package/dist/infrastructure/server/handlers/advanced/queue.js +91 -27
  338. package/dist/infrastructure/server/handlers/core.js +32 -31
  339. package/dist/infrastructure/server/handlers/cron.d.ts +4 -4
  340. package/dist/infrastructure/server/handlers/cron.js +60 -59
  341. package/dist/infrastructure/server/handlers/dashboard.d.ts +1 -1
  342. package/dist/infrastructure/server/handlers/dashboard.js +21 -8
  343. package/dist/infrastructure/server/handlers/dlq.d.ts +6 -3
  344. package/dist/infrastructure/server/handlers/dlq.js +35 -9
  345. package/dist/infrastructure/server/handlers/flow.js +2 -1
  346. package/dist/infrastructure/server/handlers/management.d.ts +5 -5
  347. package/dist/infrastructure/server/handlers/management.js +36 -9
  348. package/dist/infrastructure/server/handlers/monitoring/health.d.ts +5 -5
  349. package/dist/infrastructure/server/handlers/monitoring/health.js +45 -16
  350. package/dist/infrastructure/server/handlers/monitoring/operations.d.ts +1 -1
  351. package/dist/infrastructure/server/handlers/monitoring/operations.js +8 -1
  352. package/dist/infrastructure/server/handlers/monitoring/workers.d.ts +3 -3
  353. package/dist/infrastructure/server/handlers/monitoring/workers.js +31 -7
  354. package/dist/infrastructure/server/handlers/pushBatchValidation.d.ts +3 -1
  355. package/dist/infrastructure/server/handlers/pushBatchValidation.js +52 -7
  356. package/dist/infrastructure/server/handlers/query.d.ts +1 -1
  357. package/dist/infrastructure/server/handlers/query.js +5 -4
  358. package/dist/infrastructure/server/http.js +2 -2
  359. package/dist/infrastructure/server/httpDashboardEndpoints.d.ts +1 -1
  360. package/dist/infrastructure/server/httpDashboardEndpoints.js +19 -6
  361. package/dist/infrastructure/server/httpEndpoints.js +20 -7
  362. package/dist/infrastructure/server/httpRouteQueues.js +11 -1
  363. package/dist/infrastructure/server/shutdownCoordinator.d.ts +24 -0
  364. package/dist/infrastructure/server/shutdownCoordinator.js +106 -0
  365. package/dist/infrastructure/server/sseHandler.js +8 -3
  366. package/dist/infrastructure/server/storageAdapter.d.ts +29 -0
  367. package/dist/infrastructure/server/storageAdapter.js +61 -0
  368. package/dist/infrastructure/server/storageManager.d.ts +12 -0
  369. package/dist/infrastructure/server/storageManager.js +102 -0
  370. package/dist/infrastructure/server/tcp.js +2 -3
  371. package/dist/infrastructure/server/ws/snapshots.d.ts +1 -1
  372. package/dist/infrastructure/server/ws/snapshots.js +19 -4
  373. package/dist/infrastructure/server/wsHandler.js +10 -5
  374. package/dist/main.js +1 -1
  375. package/dist/mcp/backend/embedded/services.js +2 -1
  376. package/dist/mcp/index.d.ts +2 -2
  377. package/dist/mcp/index.js +2 -2
  378. package/dist/shared/storageHealth.d.ts +9 -0
  379. package/dist/shared/storageHealth.js +12 -0
  380. package/package.json +85 -74
@@ -0,0 +1,170 @@
1
+ export function applyPostgresJobProjection(snapshot, activeTokens, id, projection) {
2
+ snapshot.reconcile(id, projection.row, projection.completion);
3
+ const token = activeTokens.get(id);
4
+ if (token && (projection.row?.state !== 'active' || projection.row.token !== token)) {
5
+ activeTokens.delete(id);
6
+ }
7
+ }
8
+ /** Coalesced, generation-fenced repair of the local PostgreSQL read model. */
9
+ export class PostgresProjectionRefreshes {
10
+ load;
11
+ apply;
12
+ report;
13
+ retryDelayMs;
14
+ static MAX_ACTIVE_BATCHES = 2;
15
+ static MAX_REQUESTS_PER_BATCH = 1_000;
16
+ generations = new Map();
17
+ generationQueues = new Map();
18
+ pending = new Map();
19
+ active = new Set();
20
+ timer = null;
21
+ accepting = true;
22
+ started = false;
23
+ constructor(load, apply, report, retryDelayMs) {
24
+ this.load = load;
25
+ this.apply = apply;
26
+ this.report = report;
27
+ this.retryDelayMs = retryDelayMs;
28
+ }
29
+ request(id, queue) {
30
+ if (!this.accepting)
31
+ return;
32
+ const generation = this.beginGeneration(id, queue);
33
+ this.pending.set(id, { queue, generation });
34
+ this.schedule(0);
35
+ }
36
+ supersede(id) {
37
+ this.pending.delete(id);
38
+ this.generations.delete(id);
39
+ this.generationQueues.delete(id);
40
+ }
41
+ supersedeQueue(queue) {
42
+ for (const [id, generationQueue] of this.generationQueues) {
43
+ if (generationQueue === queue)
44
+ this.supersede(id);
45
+ }
46
+ }
47
+ async refreshNow(id, queue) {
48
+ const projections = await this.refreshManyNow([{ id, queue }]);
49
+ return projections.get(id) ?? { row: null, completion: null };
50
+ }
51
+ async refreshManyNow(requests) {
52
+ let remaining = [...requests];
53
+ const loaded = new Map();
54
+ for (let attempt = 0; attempt < 2 && remaining.length > 0; attempt++) {
55
+ const generations = new Map();
56
+ for (const { id, queue } of remaining) {
57
+ const generation = this.beginGeneration(id, queue);
58
+ this.pending.delete(id);
59
+ generations.set(id, generation);
60
+ }
61
+ try {
62
+ const projections = await this.load(remaining);
63
+ const invalidated = [];
64
+ for (const request of remaining) {
65
+ const projection = projections.get(request.id) ?? { row: null, completion: null };
66
+ loaded.set(request.id, projection);
67
+ if (this.generations.get(request.id) !== generations.get(request.id)) {
68
+ invalidated.push(request);
69
+ continue;
70
+ }
71
+ this.apply(request.id, projection);
72
+ this.report(request.queue, request.id, null);
73
+ this.endGeneration(request.id, generations.get(request.id));
74
+ }
75
+ remaining = invalidated;
76
+ }
77
+ catch (error) {
78
+ for (const { id, queue } of remaining) {
79
+ const generation = generations.get(id);
80
+ if (this.generations.get(id) === generation) {
81
+ this.report(queue, id, error);
82
+ this.endGeneration(id, generation);
83
+ }
84
+ }
85
+ throw error;
86
+ }
87
+ }
88
+ for (const { id, queue } of remaining)
89
+ this.request(id, queue);
90
+ return loaded;
91
+ }
92
+ start() {
93
+ if (!this.accepting || this.started)
94
+ return;
95
+ this.started = true;
96
+ this.schedule(0);
97
+ }
98
+ close() {
99
+ this.accepting = false;
100
+ this.pending.clear();
101
+ this.generations.clear();
102
+ this.generationQueues.clear();
103
+ if (this.timer)
104
+ clearTimeout(this.timer);
105
+ this.timer = null;
106
+ }
107
+ async drain() {
108
+ await Promise.all([...this.active]);
109
+ }
110
+ schedule(delayMs) {
111
+ if (!this.accepting ||
112
+ !this.started ||
113
+ this.timer ||
114
+ this.active.size >= PostgresProjectionRefreshes.MAX_ACTIVE_BATCHES ||
115
+ this.pending.size === 0) {
116
+ return;
117
+ }
118
+ this.timer = setTimeout(() => {
119
+ this.timer = null;
120
+ const execution = this.runBatch();
121
+ this.active.add(execution);
122
+ void execution.then((retry) => {
123
+ this.active.delete(execution);
124
+ this.schedule(retry ? this.retryDelayMs : 0);
125
+ });
126
+ }, delayMs);
127
+ }
128
+ async runBatch() {
129
+ const batch = [...this.pending.entries()].slice(0, PostgresProjectionRefreshes.MAX_REQUESTS_PER_BATCH);
130
+ for (const [id] of batch)
131
+ this.pending.delete(id);
132
+ if (batch.length === 0)
133
+ return false;
134
+ try {
135
+ const projections = await this.load(batch.map(([id, { queue }]) => ({ id, queue })));
136
+ for (const [id, request] of batch) {
137
+ if (this.generations.get(id) !== request.generation)
138
+ continue;
139
+ this.apply(id, projections.get(id) ?? { row: null, completion: null });
140
+ this.report(request.queue, id, null);
141
+ this.endGeneration(id, request.generation);
142
+ }
143
+ return false;
144
+ }
145
+ catch (error) {
146
+ for (const [id, request] of batch) {
147
+ if (this.generations.get(id) === request.generation && this.accepting) {
148
+ this.pending.set(id, request);
149
+ this.report(request.queue, id, error);
150
+ }
151
+ else {
152
+ this.endGeneration(id, request.generation);
153
+ }
154
+ }
155
+ return true;
156
+ }
157
+ }
158
+ beginGeneration(id, queue) {
159
+ const generation = Symbol();
160
+ this.generations.set(id, generation);
161
+ this.generationQueues.set(id, queue);
162
+ return generation;
163
+ }
164
+ endGeneration(id, generation) {
165
+ if (generation && this.generations.get(id) === generation && !this.pending.has(id)) {
166
+ this.generations.delete(id);
167
+ this.generationQueues.delete(id);
168
+ }
169
+ }
170
+ }
@@ -0,0 +1,142 @@
1
+ import { type DlqEntry, type DlqFilter, type DlqStats } from '../../domain/types/dlq';
2
+ import type { Job, JobId } from '../../domain/types/job';
3
+ import { PostgresQueueManagerState } from './state';
4
+ export declare class PostgresQueueManagerQueries extends PostgresQueueManagerState {
5
+ getJobIndex(): Map<JobId, import("../../domain/types").JobLocation>;
6
+ getCompletedJobs(): Set<JobId>;
7
+ getDepCompletions(): Set<JobId>;
8
+ getJob(jobId: JobId): Promise<Job | null>;
9
+ getJobState(jobId: JobId): Promise<string>;
10
+ getResult(jobId: JobId): unknown;
11
+ getCompletionAsync(jobId: JobId): Promise<{
12
+ found: boolean;
13
+ result: unknown;
14
+ }>;
15
+ getResultAsync(jobId: JobId): Promise<unknown>;
16
+ waitForJobCompletion(jobId: JobId, timeoutMs: number): Promise<boolean>;
17
+ getChildrenValues(parentJobId: JobId): Promise<Record<string, unknown>>;
18
+ getJobByCustomId(customId: string): Job | null;
19
+ getProgress(jobId: JobId): {
20
+ progress: number;
21
+ message: string | null;
22
+ } | null;
23
+ getJobs(queue: string, options?: {
24
+ state?: string | string[];
25
+ start?: number;
26
+ end?: number;
27
+ asc?: boolean;
28
+ }): Job[];
29
+ count(queue: string): number;
30
+ listQueues(): string[];
31
+ getCountsPerPriority(queue: string): Record<number, number>;
32
+ getDlq(queue: string, count?: number): Job[];
33
+ getDlqEntries(queue: string, filter?: DlqFilter): DlqEntry[];
34
+ getDlqCount(queue: string): number;
35
+ getDlqStats(queue: string): DlqStats;
36
+ isPaused(queue: string): boolean;
37
+ isPausedDurable(queue: string): Promise<boolean>;
38
+ getQueueLimits(queue: string): {
39
+ rateLimit: number | null;
40
+ concurrencyLimit: number | null;
41
+ };
42
+ getQueueLimitStatus(queue: string, _maxJobs?: number): {
43
+ rateLimit: {
44
+ max: number;
45
+ duration: number;
46
+ } | null;
47
+ rateLimitTtl: number;
48
+ concurrencyLimit: number | null;
49
+ maxed: boolean;
50
+ };
51
+ getQueueJobCounts(queueName: string): {
52
+ waiting: number;
53
+ prioritized: number;
54
+ delayed: number;
55
+ active: number;
56
+ completed: number;
57
+ failed: number;
58
+ 'waiting-children': number;
59
+ totalCompleted: number;
60
+ totalFailed: number;
61
+ };
62
+ getQueueJobCountsBatch(queueNames: Iterable<string>): Map<string, {
63
+ waiting: number;
64
+ prioritized: number;
65
+ delayed: number;
66
+ active: number;
67
+ completed: number;
68
+ failed: number;
69
+ 'waiting-children': number;
70
+ totalCompleted: number;
71
+ totalFailed: number;
72
+ }>;
73
+ getAllQueueJobCounts(): Map<string, {
74
+ waiting: number;
75
+ prioritized: number;
76
+ delayed: number;
77
+ active: number;
78
+ completed: number;
79
+ failed: number;
80
+ 'waiting-children': number;
81
+ totalCompleted: number;
82
+ totalFailed: number;
83
+ }>;
84
+ getPerQueueStats(): Map<string, {
85
+ waiting: number;
86
+ prioritized: number;
87
+ delayed: number;
88
+ active: number;
89
+ dlq: number;
90
+ }>;
91
+ getStats(): {
92
+ waiting: number;
93
+ prioritized: number;
94
+ delayed: number;
95
+ active: number;
96
+ dlq: number;
97
+ completed: number;
98
+ 'waiting-children': number;
99
+ totalPushed: bigint;
100
+ totalPulled: bigint;
101
+ totalCompleted: bigint;
102
+ totalFailed: bigint;
103
+ uptime: number;
104
+ cronJobs: number;
105
+ cronPending: number;
106
+ };
107
+ getQueuesSummary(): {
108
+ name: string;
109
+ paused: boolean;
110
+ counts: {
111
+ waiting: number;
112
+ prioritized: number;
113
+ active: number;
114
+ completed: number;
115
+ failed: number;
116
+ delayed: number;
117
+ };
118
+ }[];
119
+ getStorageStatus(): {
120
+ diskFull: boolean;
121
+ error: string | null;
122
+ since: number | null;
123
+ };
124
+ getMemoryStats(): {
125
+ jobIndex: number;
126
+ completedJobs: number;
127
+ jobResults: number;
128
+ jobLogs: number;
129
+ customIdMap: number;
130
+ jobLocks: number;
131
+ clientJobs: number;
132
+ clientJobsTotal: number;
133
+ pendingDepChecks: number;
134
+ stalledCandidates: number;
135
+ processingTotal: number;
136
+ queuedTotal: number;
137
+ waitingDepsTotal: number;
138
+ temporalIndexTotal: number;
139
+ delayedHeapTotal: number;
140
+ };
141
+ flushPersistence(): number;
142
+ }
@@ -0,0 +1,231 @@
1
+ import { PostgresQueueManagerState } from './state';
2
+ function jobCounts(counts, totals) {
3
+ return {
4
+ waiting: counts.waiting,
5
+ prioritized: counts.prioritized,
6
+ delayed: counts.delayed,
7
+ active: counts.active,
8
+ completed: counts.completed,
9
+ failed: counts.failed,
10
+ 'waiting-children': counts.waitingChildren,
11
+ totalCompleted: Number(totals?.totalCompleted ?? 0n),
12
+ totalFailed: Number(totals?.totalFailed ?? 0n),
13
+ };
14
+ }
15
+ export class PostgresQueueManagerQueries extends PostgresQueueManagerState {
16
+ getJobIndex() {
17
+ return this.postgresSnapshot.locations();
18
+ }
19
+ getCompletedJobs() {
20
+ return this.postgresSnapshot.completedIds();
21
+ }
22
+ getDepCompletions() {
23
+ return this.postgresSnapshot.completionIds();
24
+ }
25
+ async getJob(jobId) {
26
+ return await this.runPostgresOperation(async () => {
27
+ await this.postgresReady;
28
+ const row = await this.fetchPostgresJob(jobId);
29
+ return row?.job ?? null;
30
+ });
31
+ }
32
+ async getJobState(jobId) {
33
+ return await this.runPostgresOperation(async () => {
34
+ await this.postgresReady;
35
+ const row = await this.fetchPostgresJob(jobId);
36
+ return row?.state ?? 'unknown';
37
+ });
38
+ }
39
+ getResult(jobId) {
40
+ return this.postgresSnapshot.getResult(jobId);
41
+ }
42
+ async getCompletionAsync(jobId) {
43
+ return await this.runPostgresOperation(async () => {
44
+ await this.postgresReady;
45
+ return await this.postgresStore.getResult(jobId);
46
+ });
47
+ }
48
+ async getResultAsync(jobId) {
49
+ return (await this.getCompletionAsync(jobId)).result;
50
+ }
51
+ async waitForJobCompletion(jobId, timeoutMs) {
52
+ const controller = new AbortController();
53
+ const waiting = super.waitForJobCompletion(jobId, timeoutMs, controller.signal);
54
+ try {
55
+ const completed = (await this.getCompletionAsync(jobId)).found;
56
+ return completed || (await waiting);
57
+ }
58
+ finally {
59
+ controller.abort();
60
+ }
61
+ }
62
+ async getChildrenValues(parentJobId) {
63
+ return await this.runPostgresOperation(async () => {
64
+ await this.postgresReady;
65
+ return await this.postgresStore.getChildrenValues(parentJobId);
66
+ });
67
+ }
68
+ getJobByCustomId(customId) {
69
+ return this.postgresSnapshot.getByCustomId(customId);
70
+ }
71
+ getProgress(jobId) {
72
+ const row = this.postgresSnapshot.get(jobId);
73
+ if (row?.state !== 'active')
74
+ return null;
75
+ return { progress: row.job.progress, message: row.job.progressMessage };
76
+ }
77
+ getJobs(queue, options = {}) {
78
+ return this.postgresSnapshot.list(queue, options);
79
+ }
80
+ count(queue) {
81
+ const counts = this.postgresSnapshot.counts(queue);
82
+ return counts.waiting + counts.prioritized + counts.delayed;
83
+ }
84
+ listQueues() {
85
+ return this.postgresSnapshot.queueNames();
86
+ }
87
+ getCountsPerPriority(queue) {
88
+ return this.postgresSnapshot.priorities(queue);
89
+ }
90
+ getDlq(queue, count) {
91
+ return this.postgresSnapshot
92
+ .dlq(queue, count === undefined ? undefined : { limit: count })
93
+ .map((entry) => entry.job);
94
+ }
95
+ getDlqEntries(queue, filter) {
96
+ return this.postgresSnapshot.dlq(queue, filter);
97
+ }
98
+ getDlqCount(queue) {
99
+ return this.postgresSnapshot.counts(queue).failed;
100
+ }
101
+ getDlqStats(queue) {
102
+ const entries = this.postgresSnapshot.dlq(queue);
103
+ const now = Date.now();
104
+ const byReason = {
105
+ ["explicit_fail" /* FailureReason.ExplicitFail */]: 0,
106
+ ["max_attempts_exceeded" /* FailureReason.MaxAttemptsExceeded */]: 0,
107
+ ["timeout" /* FailureReason.Timeout */]: 0,
108
+ ["stalled" /* FailureReason.Stalled */]: 0,
109
+ ["ttl_expired" /* FailureReason.TtlExpired */]: 0,
110
+ ["worker_lost" /* FailureReason.WorkerLost */]: 0,
111
+ ["unknown" /* FailureReason.Unknown */]: 0,
112
+ };
113
+ for (const entry of entries)
114
+ byReason[entry.reason]++;
115
+ return {
116
+ total: entries.length,
117
+ byReason,
118
+ byQueue: { [queue]: entries.length },
119
+ pendingRetry: entries.filter((entry) => entry.nextRetryAt !== null && entry.nextRetryAt <= now).length,
120
+ expired: entries.filter((entry) => entry.expiresAt !== null && entry.expiresAt <= now).length,
121
+ oldestEntry: entries.length === 0 ? null : Math.min(...entries.map((entry) => entry.enteredAt)),
122
+ newestEntry: entries.length === 0 ? null : Math.max(...entries.map((entry) => entry.enteredAt)),
123
+ };
124
+ }
125
+ isPaused(queue) {
126
+ return this.postgresSnapshot.queueState(queue)?.paused ?? false;
127
+ }
128
+ async isPausedDurable(queue) {
129
+ return await this.runPostgresOperation(async () => {
130
+ await this.postgresReady;
131
+ return (await this.postgresStore.getQueueState(queue)).paused;
132
+ });
133
+ }
134
+ getQueueLimits(queue) {
135
+ const state = this.postgresSnapshot.queueState(queue);
136
+ const rateExpired = state?.rateExpiresAt !== null && (state?.rateExpiresAt ?? 0) <= Date.now();
137
+ return {
138
+ rateLimit: rateExpired ? null : (state?.rateLimit ?? null),
139
+ concurrencyLimit: state?.concurrencyLimit ?? null,
140
+ };
141
+ }
142
+ getQueueLimitStatus(queue, _maxJobs) {
143
+ const state = this.postgresSnapshot.queueState(queue);
144
+ const active = this.postgresSnapshot.counts(queue).active;
145
+ const concurrencyLimit = state?.concurrencyLimit ?? null;
146
+ const duration = state?.rateDurationMs ?? 1000;
147
+ const rateExpired = state?.rateExpiresAt !== null && (state?.rateExpiresAt ?? 0) <= Date.now();
148
+ const rateLimitTtl = state?.rateWindowStartedAt
149
+ ? Math.max(0, state.rateWindowStartedAt + duration - Date.now())
150
+ : 0;
151
+ return {
152
+ rateLimit: rateExpired || state?.rateLimit === null || state?.rateLimit === undefined
153
+ ? null
154
+ : { max: state.rateLimit, duration },
155
+ rateLimitTtl,
156
+ concurrencyLimit,
157
+ maxed: concurrencyLimit !== null && active >= concurrencyLimit,
158
+ };
159
+ }
160
+ getQueueJobCounts(queueName) {
161
+ return jobCounts(this.postgresSnapshot.counts(queueName), this.perQueueMetrics.get(queueName));
162
+ }
163
+ getQueueJobCountsBatch(queueNames) {
164
+ return new Map([...queueNames].map((queue) => [queue, this.getQueueJobCounts(queue)]));
165
+ }
166
+ getAllQueueJobCounts() {
167
+ return this.getQueueJobCountsBatch(this.listQueues());
168
+ }
169
+ getPerQueueStats() {
170
+ return new Map(this.listQueues().map((queue) => {
171
+ const counts = this.postgresSnapshot.counts(queue);
172
+ return [
173
+ queue,
174
+ {
175
+ waiting: counts.waiting,
176
+ prioritized: counts.prioritized,
177
+ delayed: counts.delayed,
178
+ active: counts.active,
179
+ dlq: counts.failed,
180
+ },
181
+ ];
182
+ }));
183
+ }
184
+ getStats() {
185
+ const counts = this.postgresSnapshot.counts();
186
+ const cron = this.cronScheduler.getStats();
187
+ return {
188
+ waiting: counts.waiting,
189
+ prioritized: counts.prioritized,
190
+ delayed: counts.delayed,
191
+ active: counts.active,
192
+ dlq: counts.failed,
193
+ completed: counts.completed,
194
+ 'waiting-children': counts.waitingChildren,
195
+ totalPushed: this.metrics.totalPushed.value,
196
+ totalPulled: this.metrics.totalPulled.value,
197
+ totalCompleted: this.metrics.totalCompleted.value,
198
+ totalFailed: this.metrics.totalFailed.value,
199
+ uptime: Date.now() - this.startTime,
200
+ cronJobs: cron.total,
201
+ cronPending: cron.pending,
202
+ };
203
+ }
204
+ getQueuesSummary() {
205
+ return this.listQueues().map((name) => {
206
+ const counts = this.postgresSnapshot.counts(name);
207
+ return {
208
+ name,
209
+ paused: this.isPaused(name),
210
+ counts: {
211
+ waiting: counts.waiting,
212
+ prioritized: counts.prioritized,
213
+ active: counts.active,
214
+ completed: counts.completed,
215
+ failed: counts.failed,
216
+ delayed: counts.delayed,
217
+ },
218
+ };
219
+ });
220
+ }
221
+ getStorageStatus() {
222
+ const health = this.postgresStore.health();
223
+ return { diskFull: false, error: health.error, since: health.since };
224
+ }
225
+ getMemoryStats() {
226
+ return { ...super.getMemoryStats(), jobIndex: this.postgresSnapshot.size() };
227
+ }
228
+ flushPersistence() {
229
+ return 0;
230
+ }
231
+ }
@@ -0,0 +1,10 @@
1
+ import type { JobId } from '../../domain/types/job';
2
+ import { PostgresQueueManagerLease } from './lease';
3
+ /** PostgreSQL-backed parent/child relationship mutations. */
4
+ export declare class PostgresQueueManagerRelationships extends PostgresQueueManagerLease {
5
+ getFailedChildrenValues(parentId: JobId): Promise<Record<string, string>>;
6
+ getIgnoredChildrenFailures(parentId: JobId): Promise<Record<string, string>>;
7
+ updateJobParent(childId: JobId, parentId: JobId): Promise<void>;
8
+ removeChildDependency(childId: JobId): Promise<boolean>;
9
+ removeUnprocessedChildren(parentId: JobId): Promise<void>;
10
+ }
@@ -0,0 +1,45 @@
1
+ import { PostgresQueueManagerLease } from './lease';
2
+ /** PostgreSQL-backed parent/child relationship mutations. */
3
+ export class PostgresQueueManagerRelationships extends PostgresQueueManagerLease {
4
+ async getFailedChildrenValues(parentId) {
5
+ return await this.runPostgresOperation(async () => {
6
+ await this.postgresReady;
7
+ return await this.postgresStore.getFailedChildrenValues(parentId);
8
+ });
9
+ }
10
+ async getIgnoredChildrenFailures(parentId) {
11
+ return await this.runPostgresOperation(async () => {
12
+ await this.postgresReady;
13
+ return await this.postgresStore.getIgnoredChildrenFailures(parentId);
14
+ });
15
+ }
16
+ async updateJobParent(childId, parentId) {
17
+ return await this.runPostgresOperation(async () => {
18
+ await this.postgresReady;
19
+ await this.postgresStore.updateParent(childId, parentId);
20
+ await Promise.all([this.refreshJob(childId), this.refreshJob(parentId)]);
21
+ });
22
+ }
23
+ async removeChildDependency(childId) {
24
+ return await this.runPostgresOperation(async () => {
25
+ await this.postgresReady;
26
+ const child = await this.postgresStore.getJob(childId);
27
+ const parentId = child?.job.parentId ?? null;
28
+ const removed = await this.postgresStore.removeDependency(childId);
29
+ if (removed) {
30
+ await this.refreshJob(childId);
31
+ if (parentId)
32
+ await this.refreshJob(parentId);
33
+ }
34
+ return removed;
35
+ });
36
+ }
37
+ async removeUnprocessedChildren(parentId) {
38
+ return await this.runPostgresOperation(async () => {
39
+ await this.postgresReady;
40
+ const removed = await this.postgresStore.removeUnprocessedChildren(parentId);
41
+ if (removed.length > 0)
42
+ await this.refreshJobs([parentId, ...removed]);
43
+ });
44
+ }
45
+ }
@@ -0,0 +1,31 @@
1
+ import type { CronJob, CronJobInput } from '../../domain/types/cron';
2
+ import type { JobId } from '../../domain/types/job';
3
+ import type { QueueMetrics, QueueMetricType } from '../../domain/types/metrics';
4
+ import type { CreateWorkerOptions, Worker } from '../../domain/types/worker';
5
+ import { PostgresQueueManagerControl } from './control';
6
+ /** Durable PostgreSQL-backed broker services shared across every broker instance. */
7
+ export declare class PostgresQueueManagerServices extends PostgresQueueManagerControl {
8
+ registerWorker(name: string, queues: string[], concurrency?: number, options?: CreateWorkerOptions): Worker;
9
+ registerWorkerDurable(name: string, queues: string[], concurrency?: number, options?: CreateWorkerOptions): Promise<Worker>;
10
+ unregisterWorker(id: string): boolean;
11
+ unregisterWorkerDurable(id: string, clientId?: string): Promise<boolean>;
12
+ unregisterWorkersByClientId(clientId: string): number;
13
+ heartbeatWorkerDurable(id: string, stats?: {
14
+ activeJobs?: number;
15
+ processed?: number;
16
+ failed?: number;
17
+ }, clientId?: string): Promise<boolean>;
18
+ listWorkersDurable(): Promise<Worker[]>;
19
+ findMissingDependenciesDurable(ids: readonly JobId[]): Promise<JobId[]>;
20
+ addCron(input: CronJobInput): CronJob;
21
+ addCronDurable(input: CronJobInput): Promise<CronJob>;
22
+ removeCron(name: string): boolean;
23
+ removeCronDurable(name: string): Promise<boolean>;
24
+ getCronDurable(name: string): Promise<CronJob | undefined>;
25
+ listCronsDurable(): Promise<CronJob[]>;
26
+ addLogDurable(id: JobId, message: string, level?: 'info' | 'warn' | 'error'): Promise<boolean>;
27
+ getLogsDurable(id: JobId): Promise<import("../../domain/types/worker").JobLogEntry[]>;
28
+ clearLogsDurable(id: JobId, keepLogs?: number): Promise<void>;
29
+ getQueueMetricsDurable(queue: string, type: QueueMetricType, start?: number, end?: number): Promise<QueueMetrics>;
30
+ trimQueueEventsDurable(queue: string, maxLength: number): Promise<number>;
31
+ }