bunqueue 1.0.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 (215) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +640 -0
  3. package/dist/application/dlqManager.d.ts +19 -0
  4. package/dist/application/dlqManager.d.ts.map +1 -0
  5. package/dist/application/dlqManager.js +44 -0
  6. package/dist/application/dlqManager.js.map +1 -0
  7. package/dist/application/eventsManager.d.ts +28 -0
  8. package/dist/application/eventsManager.d.ts.map +1 -0
  9. package/dist/application/eventsManager.js +59 -0
  10. package/dist/application/eventsManager.js.map +1 -0
  11. package/dist/application/jobLogsManager.d.ts +20 -0
  12. package/dist/application/jobLogsManager.d.ts.map +1 -0
  13. package/dist/application/jobLogsManager.js +28 -0
  14. package/dist/application/jobLogsManager.js.map +1 -0
  15. package/dist/application/metricsExporter.d.ts +24 -0
  16. package/dist/application/metricsExporter.d.ts.map +1 -0
  17. package/dist/application/metricsExporter.js +80 -0
  18. package/dist/application/metricsExporter.js.map +1 -0
  19. package/dist/application/operations/ack.d.ts +48 -0
  20. package/dist/application/operations/ack.d.ts.map +1 -0
  21. package/dist/application/operations/ack.js +109 -0
  22. package/dist/application/operations/ack.js.map +1 -0
  23. package/dist/application/operations/index.d.ts +10 -0
  24. package/dist/application/operations/index.d.ts.map +1 -0
  25. package/dist/application/operations/index.js +10 -0
  26. package/dist/application/operations/index.js.map +1 -0
  27. package/dist/application/operations/jobManagement.d.ts +32 -0
  28. package/dist/application/operations/jobManagement.d.ts.map +1 -0
  29. package/dist/application/operations/jobManagement.js +122 -0
  30. package/dist/application/operations/jobManagement.js.map +1 -0
  31. package/dist/application/operations/pull.d.ts +36 -0
  32. package/dist/application/operations/pull.d.ts.map +1 -0
  33. package/dist/application/operations/pull.js +109 -0
  34. package/dist/application/operations/pull.js.map +1 -0
  35. package/dist/application/operations/push.d.ts +36 -0
  36. package/dist/application/operations/push.d.ts.map +1 -0
  37. package/dist/application/operations/push.js +94 -0
  38. package/dist/application/operations/push.js.map +1 -0
  39. package/dist/application/operations/queryOperations.d.ts +33 -0
  40. package/dist/application/operations/queryOperations.d.ts.map +1 -0
  41. package/dist/application/operations/queryOperations.js +57 -0
  42. package/dist/application/operations/queryOperations.js.map +1 -0
  43. package/dist/application/operations/queueControl.d.ts +32 -0
  44. package/dist/application/operations/queueControl.d.ts.map +1 -0
  45. package/dist/application/operations/queueControl.js +72 -0
  46. package/dist/application/operations/queueControl.js.map +1 -0
  47. package/dist/application/queueManager.d.ts +113 -0
  48. package/dist/application/queueManager.d.ts.map +1 -0
  49. package/dist/application/queueManager.js +406 -0
  50. package/dist/application/queueManager.js.map +1 -0
  51. package/dist/application/webhookManager.d.ts +35 -0
  52. package/dist/application/webhookManager.d.ts.map +1 -0
  53. package/dist/application/webhookManager.js +109 -0
  54. package/dist/application/webhookManager.js.map +1 -0
  55. package/dist/application/workerManager.d.ts +48 -0
  56. package/dist/application/workerManager.d.ts.map +1 -0
  57. package/dist/application/workerManager.js +121 -0
  58. package/dist/application/workerManager.js.map +1 -0
  59. package/dist/domain/queue/index.d.ts +6 -0
  60. package/dist/domain/queue/index.d.ts.map +1 -0
  61. package/dist/domain/queue/index.js +6 -0
  62. package/dist/domain/queue/index.js.map +1 -0
  63. package/dist/domain/queue/priorityQueue.d.ts +45 -0
  64. package/dist/domain/queue/priorityQueue.d.ts.map +1 -0
  65. package/dist/domain/queue/priorityQueue.js +203 -0
  66. package/dist/domain/queue/priorityQueue.js.map +1 -0
  67. package/dist/domain/queue/shard.d.ts +98 -0
  68. package/dist/domain/queue/shard.d.ts.map +1 -0
  69. package/dist/domain/queue/shard.js +245 -0
  70. package/dist/domain/queue/shard.js.map +1 -0
  71. package/dist/domain/types/command.d.ts +270 -0
  72. package/dist/domain/types/command.d.ts.map +1 -0
  73. package/dist/domain/types/command.js +6 -0
  74. package/dist/domain/types/command.js.map +1 -0
  75. package/dist/domain/types/cron.d.ts +32 -0
  76. package/dist/domain/types/cron.d.ts.map +1 -0
  77. package/dist/domain/types/cron.js +31 -0
  78. package/dist/domain/types/cron.js.map +1 -0
  79. package/dist/domain/types/index.d.ts +9 -0
  80. package/dist/domain/types/index.d.ts.map +1 -0
  81. package/dist/domain/types/index.js +9 -0
  82. package/dist/domain/types/index.js.map +1 -0
  83. package/dist/domain/types/job.d.ts +94 -0
  84. package/dist/domain/types/job.d.ts.map +1 -0
  85. package/dist/domain/types/job.js +81 -0
  86. package/dist/domain/types/job.js.map +1 -0
  87. package/dist/domain/types/queue.d.ts +86 -0
  88. package/dist/domain/types/queue.d.ts.map +1 -0
  89. package/dist/domain/types/queue.js +84 -0
  90. package/dist/domain/types/queue.js.map +1 -0
  91. package/dist/domain/types/response.d.ts +158 -0
  92. package/dist/domain/types/response.d.ts.map +1 -0
  93. package/dist/domain/types/response.js +86 -0
  94. package/dist/domain/types/response.js.map +1 -0
  95. package/dist/domain/types/webhook.d.ts +33 -0
  96. package/dist/domain/types/webhook.d.ts.map +1 -0
  97. package/dist/domain/types/webhook.js +20 -0
  98. package/dist/domain/types/webhook.js.map +1 -0
  99. package/dist/domain/types/worker.d.ts +27 -0
  100. package/dist/domain/types/worker.d.ts.map +1 -0
  101. package/dist/domain/types/worker.js +27 -0
  102. package/dist/domain/types/worker.js.map +1 -0
  103. package/dist/infrastructure/persistence/index.d.ts +6 -0
  104. package/dist/infrastructure/persistence/index.d.ts.map +1 -0
  105. package/dist/infrastructure/persistence/index.js +6 -0
  106. package/dist/infrastructure/persistence/index.js.map +1 -0
  107. package/dist/infrastructure/persistence/schema.d.ts +14 -0
  108. package/dist/infrastructure/persistence/schema.d.ts.map +1 -0
  109. package/dist/infrastructure/persistence/schema.js +123 -0
  110. package/dist/infrastructure/persistence/schema.js.map +1 -0
  111. package/dist/infrastructure/persistence/sqlite.d.ts +42 -0
  112. package/dist/infrastructure/persistence/sqlite.d.ts.map +1 -0
  113. package/dist/infrastructure/persistence/sqlite.js +164 -0
  114. package/dist/infrastructure/persistence/sqlite.js.map +1 -0
  115. package/dist/infrastructure/persistence/statements.d.ts +55 -0
  116. package/dist/infrastructure/persistence/statements.d.ts.map +1 -0
  117. package/dist/infrastructure/persistence/statements.js +42 -0
  118. package/dist/infrastructure/persistence/statements.js.map +1 -0
  119. package/dist/infrastructure/scheduler/cronParser.d.ts +44 -0
  120. package/dist/infrastructure/scheduler/cronParser.d.ts.map +1 -0
  121. package/dist/infrastructure/scheduler/cronParser.js +90 -0
  122. package/dist/infrastructure/scheduler/cronParser.js.map +1 -0
  123. package/dist/infrastructure/scheduler/cronScheduler.d.ts +68 -0
  124. package/dist/infrastructure/scheduler/cronScheduler.d.ts.map +1 -0
  125. package/dist/infrastructure/scheduler/cronScheduler.js +172 -0
  126. package/dist/infrastructure/scheduler/cronScheduler.js.map +1 -0
  127. package/dist/infrastructure/scheduler/index.d.ts +6 -0
  128. package/dist/infrastructure/scheduler/index.d.ts.map +1 -0
  129. package/dist/infrastructure/scheduler/index.js +6 -0
  130. package/dist/infrastructure/scheduler/index.js.map +1 -0
  131. package/dist/infrastructure/server/handler.d.ts +13 -0
  132. package/dist/infrastructure/server/handler.d.ts.map +1 -0
  133. package/dist/infrastructure/server/handler.js +167 -0
  134. package/dist/infrastructure/server/handler.js.map +1 -0
  135. package/dist/infrastructure/server/handlers/advanced.d.ts +68 -0
  136. package/dist/infrastructure/server/handlers/advanced.d.ts.map +1 -0
  137. package/dist/infrastructure/server/handlers/advanced.js +99 -0
  138. package/dist/infrastructure/server/handlers/advanced.js.map +1 -0
  139. package/dist/infrastructure/server/handlers/core.d.ts +36 -0
  140. package/dist/infrastructure/server/handlers/core.d.ts.map +1 -0
  141. package/dist/infrastructure/server/handlers/core.js +82 -0
  142. package/dist/infrastructure/server/handlers/core.js.map +1 -0
  143. package/dist/infrastructure/server/handlers/cron.d.ts +20 -0
  144. package/dist/infrastructure/server/handlers/cron.d.ts.map +1 -0
  145. package/dist/infrastructure/server/handlers/cron.js +56 -0
  146. package/dist/infrastructure/server/handlers/cron.js.map +1 -0
  147. package/dist/infrastructure/server/handlers/dlq.d.ts +20 -0
  148. package/dist/infrastructure/server/handlers/dlq.d.ts.map +1 -0
  149. package/dist/infrastructure/server/handlers/dlq.js +31 -0
  150. package/dist/infrastructure/server/handlers/dlq.js.map +1 -0
  151. package/dist/infrastructure/server/handlers/index.d.ts +7 -0
  152. package/dist/infrastructure/server/handlers/index.d.ts.map +1 -0
  153. package/dist/infrastructure/server/handlers/index.js +7 -0
  154. package/dist/infrastructure/server/handlers/index.js.map +1 -0
  155. package/dist/infrastructure/server/handlers/management.d.ts +36 -0
  156. package/dist/infrastructure/server/handlers/management.d.ts.map +1 -0
  157. package/dist/infrastructure/server/handlers/management.js +75 -0
  158. package/dist/infrastructure/server/handlers/management.js.map +1 -0
  159. package/dist/infrastructure/server/handlers/monitoring.d.ts +18 -0
  160. package/dist/infrastructure/server/handlers/monitoring.d.ts.map +1 -0
  161. package/dist/infrastructure/server/handlers/monitoring.js +102 -0
  162. package/dist/infrastructure/server/handlers/monitoring.js.map +1 -0
  163. package/dist/infrastructure/server/handlers/query.d.ts +32 -0
  164. package/dist/infrastructure/server/handlers/query.d.ts.map +1 -0
  165. package/dist/infrastructure/server/handlers/query.js +61 -0
  166. package/dist/infrastructure/server/handlers/query.js.map +1 -0
  167. package/dist/infrastructure/server/http.d.ts +43 -0
  168. package/dist/infrastructure/server/http.d.ts.map +1 -0
  169. package/dist/infrastructure/server/http.js +344 -0
  170. package/dist/infrastructure/server/http.js.map +1 -0
  171. package/dist/infrastructure/server/index.d.ts +8 -0
  172. package/dist/infrastructure/server/index.d.ts.map +1 -0
  173. package/dist/infrastructure/server/index.js +8 -0
  174. package/dist/infrastructure/server/index.js.map +1 -0
  175. package/dist/infrastructure/server/protocol.d.ts +44 -0
  176. package/dist/infrastructure/server/protocol.d.ts.map +1 -0
  177. package/dist/infrastructure/server/protocol.js +129 -0
  178. package/dist/infrastructure/server/protocol.js.map +1 -0
  179. package/dist/infrastructure/server/rateLimiter.d.ts +31 -0
  180. package/dist/infrastructure/server/rateLimiter.d.ts.map +1 -0
  181. package/dist/infrastructure/server/rateLimiter.js +79 -0
  182. package/dist/infrastructure/server/rateLimiter.js.map +1 -0
  183. package/dist/infrastructure/server/tcp.d.ts +36 -0
  184. package/dist/infrastructure/server/tcp.d.ts.map +1 -0
  185. package/dist/infrastructure/server/tcp.js +101 -0
  186. package/dist/infrastructure/server/tcp.js.map +1 -0
  187. package/dist/infrastructure/server/types.d.ts +11 -0
  188. package/dist/infrastructure/server/types.d.ts.map +1 -0
  189. package/dist/infrastructure/server/types.js +5 -0
  190. package/dist/infrastructure/server/types.js.map +1 -0
  191. package/dist/main.d.ts +6 -0
  192. package/dist/main.d.ts.map +1 -0
  193. package/dist/main.js +111 -0
  194. package/dist/main.js.map +1 -0
  195. package/dist/shared/hash.d.ts +30 -0
  196. package/dist/shared/hash.d.ts.map +1 -0
  197. package/dist/shared/hash.js +69 -0
  198. package/dist/shared/hash.js.map +1 -0
  199. package/dist/shared/index.d.ts +6 -0
  200. package/dist/shared/index.d.ts.map +1 -0
  201. package/dist/shared/index.js +6 -0
  202. package/dist/shared/index.js.map +1 -0
  203. package/dist/shared/lock.d.ts +70 -0
  204. package/dist/shared/lock.d.ts.map +1 -0
  205. package/dist/shared/lock.js +207 -0
  206. package/dist/shared/lock.js.map +1 -0
  207. package/dist/shared/logger.d.ts +38 -0
  208. package/dist/shared/logger.d.ts.map +1 -0
  209. package/dist/shared/logger.js +74 -0
  210. package/dist/shared/logger.js.map +1 -0
  211. package/dist/shared/serialization.d.ts +23 -0
  212. package/dist/shared/serialization.d.ts.map +1 -0
  213. package/dist/shared/serialization.js +63 -0
  214. package/dist/shared/serialization.js.map +1 -0
  215. package/package.json +82 -0
@@ -0,0 +1,44 @@
1
+ /**
2
+ * DLQ Manager
3
+ * Dead Letter Queue operations
4
+ */
5
+ import { shardIndex } from '../shared/hash';
6
+ /** Get jobs from DLQ */
7
+ export function getDlqJobs(queue, ctx, count) {
8
+ const idx = shardIndex(queue);
9
+ const jobs = ctx.shards[idx].getDlq(queue);
10
+ return count ? jobs.slice(0, count) : jobs;
11
+ }
12
+ /** Retry jobs from DLQ */
13
+ export function retryDlqJobs(queue, ctx, jobId) {
14
+ const idx = shardIndex(queue);
15
+ const shard = ctx.shards[idx];
16
+ if (jobId) {
17
+ const job = shard.removeFromDlq(queue, jobId);
18
+ if (job) {
19
+ job.attempts = 0;
20
+ job.runAt = Date.now();
21
+ shard.getQueue(queue).push(job);
22
+ ctx.jobIndex.set(job.id, { type: 'queue', shardIdx: idx, queueName: queue });
23
+ return 1;
24
+ }
25
+ return 0;
26
+ }
27
+ // Retry all
28
+ const jobs = shard.getDlq(queue);
29
+ const count = jobs.length;
30
+ shard.clearDlq(queue);
31
+ for (const job of jobs) {
32
+ job.attempts = 0;
33
+ job.runAt = Date.now();
34
+ shard.getQueue(queue).push(job);
35
+ ctx.jobIndex.set(job.id, { type: 'queue', shardIdx: idx, queueName: queue });
36
+ }
37
+ return count;
38
+ }
39
+ /** Purge all jobs from DLQ */
40
+ export function purgeDlqJobs(queue, ctx) {
41
+ const idx = shardIndex(queue);
42
+ return ctx.shards[idx].clearDlq(queue);
43
+ }
44
+ //# sourceMappingURL=dlqManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dlqManager.js","sourceRoot":"","sources":["../../src/application/dlqManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAQ5C,wBAAwB;AACxB,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,GAAe,EAAE,KAAc;IACvE,MAAM,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAC9B,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3C,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK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AC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IAC/E,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,8BAA8B;AAC9B,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,GAAe;IACzD,MAAM,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Events Manager
3
+ * Job event subscription and broadcasting
4
+ */
5
+ import type { JobId } from '../domain/types/job';
6
+ import { EventType, type JobEvent } from '../domain/types/queue';
7
+ import type { WebhookManager } from './webhookManager';
8
+ /** Event subscriber callback */
9
+ export type EventSubscriber = (event: JobEvent) => void;
10
+ /** Events manager class */
11
+ export declare class EventsManager {
12
+ private readonly webhookManager;
13
+ private readonly subscribers;
14
+ constructor(webhookManager: WebhookManager);
15
+ /** Subscribe to job events */
16
+ subscribe(callback: EventSubscriber): () => void;
17
+ /** Broadcast event to all subscribers */
18
+ broadcast(event: Partial<JobEvent> & {
19
+ eventType: EventType;
20
+ queue: string;
21
+ jobId: JobId;
22
+ timestamp: number;
23
+ error?: string;
24
+ }): void;
25
+ /** Map internal event type to webhook event */
26
+ private mapEventToWebhook;
27
+ }
28
+ //# sourceMappingURL=eventsManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventsManager.d.ts","sourceRoot":"","sources":["../../src/application/eventsManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGvD,gCAAgC;AAChC,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;AAExD,2BAA2B;AAC3B,qBAAa,aAAa;IAGZ,OAAO,CAAC,QAAQ,CAAC,cAAc;IAF3C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAyB;gBAExB,cAAc,EAAE,cAAc;IAE3D,8BAA8B;IAC9B,SAAS,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,IAAI;IAQhD,yCAAyC;IACzC,SAAS,CACP,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG;QACzB,SAAS,EAAE,SAAS,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,KAAK,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GACA,IAAI;IAsBP,+CAA+C;IAC/C,OAAO,CAAC,iBAAiB;CAc1B"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Events Manager
3
+ * Job event subscription and broadcasting
4
+ */
5
+ /** Events manager class */
6
+ export class EventsManager {
7
+ webhookManager;
8
+ subscribers = [];
9
+ constructor(webhookManager) {
10
+ this.webhookManager = webhookManager;
11
+ }
12
+ /** Subscribe to job events */
13
+ subscribe(callback) {
14
+ this.subscribers.push(callback);
15
+ return () => {
16
+ const idx = this.subscribers.indexOf(callback);
17
+ if (idx !== -1)
18
+ this.subscribers.splice(idx, 1);
19
+ };
20
+ }
21
+ /** Broadcast event to all subscribers */
22
+ broadcast(event) {
23
+ // Notify subscribers
24
+ for (const sub of this.subscribers) {
25
+ try {
26
+ sub(event);
27
+ }
28
+ catch {
29
+ // Ignore subscriber errors
30
+ }
31
+ }
32
+ // Trigger webhooks
33
+ const webhookEvent = this.mapEventToWebhook(event.eventType);
34
+ if (webhookEvent) {
35
+ this.webhookManager
36
+ .trigger(webhookEvent, String(event.jobId), event.queue, {
37
+ data: event.data,
38
+ error: event.error,
39
+ })
40
+ .catch(() => { });
41
+ }
42
+ }
43
+ /** Map internal event type to webhook event */
44
+ mapEventToWebhook(eventType) {
45
+ switch (eventType) {
46
+ case "pushed" /* EventType.Pushed */:
47
+ return 'job.pushed';
48
+ case "pulled" /* EventType.Pulled */:
49
+ return 'job.started';
50
+ case "completed" /* EventType.Completed */:
51
+ return 'job.completed';
52
+ case "failed" /* EventType.Failed */:
53
+ return 'job.failed';
54
+ default:
55
+ return null;
56
+ }
57
+ }
58
+ }
59
+ //# sourceMappingURL=eventsManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventsManager.js","sourceRoot":"","sources":["../../src/application/eventsManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,2BAA2B;AAC3B,MAAM,OAAO,aAAa;IAGK;IAFZ,WAAW,GAAsB,EAAE,CAAC;IAErD,YAA6B,cAA8B;QAA9B,mBAAc,GAAd,cAAc,CAAgB;IAAG,CAAC;IAE/D,8BAA8B;IAC9B,SAAS,CAAC,QAAyB;QACjC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,OAAO,GAAG,EAAE;YACV,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC/C,IAAI,GAAG,KAAK,CAAC,CAAC;gBAAE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAClD,CAAC,CAAC;IACJ,CAAC;IAED,yCAAyC;IACzC,SAAS,CACP,KAMC;QAED,qBAAqB;QACrB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnC,IAAI,CAAC;gBACH,GAAG,CAAC,KAAiB,CAAC,CAAC;YACzB,CAAC;YAAC,MAAM,CAAC;gBACP,2BAA2B;YAC7B,CAAC;QACH,CAAC;QAED,mBAAmB;QACnB,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC7D,IAAI,YAAY,EAAE,CAAC;YACjB,IAAI,CAAC,cAAc;iBAChB,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE;gBACvD,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,KAAK,EAAE,KAAK,CAAC,KAAK;aACnB,CAAC;iBACD,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED,+CAA+C;IACvC,iBAAiB,CAAC,SAAoB;QAC5C,QAAQ,SAAS,EAAE,CAAC;YAClB;gBACE,OAAO,YAAY,CAAC;YACtB;gBACE,OAAO,aAAa,CAAC;YACvB;gBACE,OAAO,eAAe,CAAC;YACzB;gBACE,OAAO,YAAY,CAAC;YACtB;gBACE,OAAO,IAAI,CAAC;QAChB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Job Logs Manager
3
+ * Per-job logging operations
4
+ */
5
+ import type { JobId } from '../domain/types/job';
6
+ import { type JobLogEntry } from '../domain/types/worker';
7
+ import type { JobLocation } from '../domain/types/queue';
8
+ /** Context for job logs operations */
9
+ export interface JobLogsContext {
10
+ jobIndex: Map<JobId, JobLocation>;
11
+ jobLogs: Map<JobId, JobLogEntry[]>;
12
+ maxLogsPerJob: number;
13
+ }
14
+ /** Add log entry to a job */
15
+ export declare function addJobLog(jobId: JobId, message: string, ctx: JobLogsContext, level?: 'info' | 'warn' | 'error'): boolean;
16
+ /** Get logs for a job */
17
+ export declare function getJobLogs(jobId: JobId, ctx: JobLogsContext): JobLogEntry[];
18
+ /** Clear logs for a job */
19
+ export declare function clearJobLogs(jobId: JobId, ctx: JobLogsContext): void;
20
+ //# sourceMappingURL=jobLogsManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jobLogsManager.d.ts","sourceRoot":"","sources":["../../src/application/jobLogsManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,sCAAsC;AACtC,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAClC,OAAO,EAAE,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;IACnC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,6BAA6B;AAC7B,wBAAgB,SAAS,CACvB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,cAAc,EACnB,KAAK,GAAE,MAAM,GAAG,MAAM,GAAG,OAAgB,GACxC,OAAO,CAcT;AAED,yBAAyB;AACzB,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,GAAG,WAAW,EAAE,CAE3E;AAED,2BAA2B;AAC3B,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,GAAG,IAAI,CAEpE"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Job Logs Manager
3
+ * Per-job logging operations
4
+ */
5
+ import { createLogEntry } from '../domain/types/worker';
6
+ /** Add log entry to a job */
7
+ export function addJobLog(jobId, message, ctx, level = 'info') {
8
+ const location = ctx.jobIndex.get(jobId);
9
+ if (!location)
10
+ return false;
11
+ const logs = ctx.jobLogs.get(jobId) ?? [];
12
+ logs.push(createLogEntry(message, level));
13
+ // Keep bounded
14
+ if (logs.length > ctx.maxLogsPerJob) {
15
+ logs.splice(0, logs.length - ctx.maxLogsPerJob);
16
+ }
17
+ ctx.jobLogs.set(jobId, logs);
18
+ return true;
19
+ }
20
+ /** Get logs for a job */
21
+ export function getJobLogs(jobId, ctx) {
22
+ return ctx.jobLogs.get(jobId) ?? [];
23
+ }
24
+ /** Clear logs for a job */
25
+ export function clearJobLogs(jobId, ctx) {
26
+ ctx.jobLogs.delete(jobId);
27
+ }
28
+ //# sourceMappingURL=jobLogsManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jobLogsManager.js","sourceRoot":"","sources":["../../src/application/jobLogsManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAoB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAU1E,6BAA6B;AAC7B,MAAM,UAAU,SAAS,CACvB,KAAY,EACZ,OAAe,EACf,GAAmB,EACnB,QAAmC,MAAM;IAEzC,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACzC,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAE5B,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1C,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IAE1C,eAAe;IACf,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,aAAa,EAAE,CAAC;QACpC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC;IAClD,CAAC;IAED,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC7B,OAAO,IAAI,CAAC;AACd,CAAC;AAED,yBAAyB;AACzB,MAAM,UAAU,UAAU,CAAC,KAAY,EAAE,GAAmB;IAC1D,OAAO,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;AACtC,CAAC;AAED,2BAA2B;AAC3B,MAAM,UAAU,YAAY,CAAC,KAAY,EAAE,GAAmB;IAC5D,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Metrics Exporter
3
+ * Prometheus metrics generation
4
+ */
5
+ import type { WorkerManager } from './workerManager';
6
+ import type { WebhookManager } from './webhookManager';
7
+ /** Stats data structure */
8
+ export interface QueueStats {
9
+ waiting: number;
10
+ delayed: number;
11
+ active: number;
12
+ dlq: number;
13
+ completed: number;
14
+ totalPushed: bigint;
15
+ totalPulled: bigint;
16
+ totalCompleted: bigint;
17
+ totalFailed: bigint;
18
+ uptime: number;
19
+ cronJobs: number;
20
+ cronPending: number;
21
+ }
22
+ /** Generate Prometheus metrics */
23
+ export declare function generatePrometheusMetrics(stats: QueueStats, workerManager: WorkerManager, webhookManager: WebhookManager): string;
24
+ //# sourceMappingURL=metricsExporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metricsExporter.d.ts","sourceRoot":"","sources":["../../src/application/metricsExporter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,2BAA2B;AAC3B,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,kCAAkC;AAClC,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,UAAU,EACjB,aAAa,EAAE,aAAa,EAC5B,cAAc,EAAE,cAAc,GAC7B,MAAM,CA2ER"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Metrics Exporter
3
+ * Prometheus metrics generation
4
+ */
5
+ /** Generate Prometheus metrics */
6
+ export function generatePrometheusMetrics(stats, workerManager, webhookManager) {
7
+ const workerStats = workerManager.getStats();
8
+ const webhookStats = webhookManager.getStats();
9
+ const lines = [
10
+ '# HELP bunq_jobs_waiting Number of jobs waiting in queue',
11
+ '# TYPE bunq_jobs_waiting gauge',
12
+ `bunq_jobs_waiting ${stats.waiting}`,
13
+ '',
14
+ '# HELP bunq_jobs_delayed Number of delayed jobs',
15
+ '# TYPE bunq_jobs_delayed gauge',
16
+ `bunq_jobs_delayed ${stats.delayed}`,
17
+ '',
18
+ '# HELP bunq_jobs_active Number of jobs being processed',
19
+ '# TYPE bunq_jobs_active gauge',
20
+ `bunq_jobs_active ${stats.active}`,
21
+ '',
22
+ '# HELP bunq_jobs_dlq Number of jobs in dead letter queue',
23
+ '# TYPE bunq_jobs_dlq gauge',
24
+ `bunq_jobs_dlq ${stats.dlq}`,
25
+ '',
26
+ '# HELP bunq_jobs_completed Number of completed jobs',
27
+ '# TYPE bunq_jobs_completed gauge',
28
+ `bunq_jobs_completed ${stats.completed}`,
29
+ '',
30
+ '# HELP bunq_jobs_pushed_total Total jobs pushed',
31
+ '# TYPE bunq_jobs_pushed_total counter',
32
+ `bunq_jobs_pushed_total ${stats.totalPushed}`,
33
+ '',
34
+ '# HELP bunq_jobs_pulled_total Total jobs pulled',
35
+ '# TYPE bunq_jobs_pulled_total counter',
36
+ `bunq_jobs_pulled_total ${stats.totalPulled}`,
37
+ '',
38
+ '# HELP bunq_jobs_completed_total Total jobs completed',
39
+ '# TYPE bunq_jobs_completed_total counter',
40
+ `bunq_jobs_completed_total ${stats.totalCompleted}`,
41
+ '',
42
+ '# HELP bunq_jobs_failed_total Total jobs failed',
43
+ '# TYPE bunq_jobs_failed_total counter',
44
+ `bunq_jobs_failed_total ${stats.totalFailed}`,
45
+ '',
46
+ '# HELP bunq_uptime_seconds Server uptime in seconds',
47
+ '# TYPE bunq_uptime_seconds gauge',
48
+ `bunq_uptime_seconds ${Math.floor(stats.uptime / 1000)}`,
49
+ '',
50
+ '# HELP bunq_cron_jobs_total Total number of cron jobs',
51
+ '# TYPE bunq_cron_jobs_total gauge',
52
+ `bunq_cron_jobs_total ${stats.cronJobs}`,
53
+ '',
54
+ '# HELP bunq_workers_total Total number of registered workers',
55
+ '# TYPE bunq_workers_total gauge',
56
+ `bunq_workers_total ${workerStats.total}`,
57
+ '',
58
+ '# HELP bunq_workers_active Number of active workers',
59
+ '# TYPE bunq_workers_active gauge',
60
+ `bunq_workers_active ${workerStats.active}`,
61
+ '',
62
+ '# HELP bunq_workers_processed_total Total jobs processed by workers',
63
+ '# TYPE bunq_workers_processed_total counter',
64
+ `bunq_workers_processed_total ${workerStats.totalProcessed}`,
65
+ '',
66
+ '# HELP bunq_workers_failed_total Total jobs failed by workers',
67
+ '# TYPE bunq_workers_failed_total counter',
68
+ `bunq_workers_failed_total ${workerStats.totalFailed}`,
69
+ '',
70
+ '# HELP bunq_webhooks_total Total number of webhooks',
71
+ '# TYPE bunq_webhooks_total gauge',
72
+ `bunq_webhooks_total ${webhookStats.total}`,
73
+ '',
74
+ '# HELP bunq_webhooks_enabled Number of enabled webhooks',
75
+ '# TYPE bunq_webhooks_enabled gauge',
76
+ `bunq_webhooks_enabled ${webhookStats.enabled}`,
77
+ ];
78
+ return lines.join('\n');
79
+ }
80
+ //# sourceMappingURL=metricsExporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metricsExporter.js","sourceRoot":"","sources":["../../src/application/metricsExporter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqBH,kCAAkC;AAClC,MAAM,UAAU,yBAAyB,CACvC,KAAiB,EACjB,aAA4B,EAC5B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E;QACrE,6CAA6C;QAC7C,gCAAgC,WAAW,CAAC,cAAc,EAAE;QAC5D,EAAE;QACF,+DAA+D;QAC/D,0CAA0C;QAC1C,6BAA6B,WAAW,CAAC,WAAW,EAAE;QACtD,EAAE;QACF,qDAAqD;QACrD,kCAAkC;QAClC,uBAAuB,YAAY,CAAC,KAAK,EAAE;QAC3C,EAAE;QACF,yDAAyD;QACzD,oCAAoC;QACpC,yBAAyB,YAAY,CAAC,OAAO,EAAE;KAChD,CAAC;IAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Ack/Fail Operations
3
+ * Job acknowledgement and failure handling
4
+ */
5
+ import { type Job, type JobId } from '../../domain/types/job';
6
+ import type { JobLocation, EventType } from '../../domain/types/queue';
7
+ import type { Shard } from '../../domain/queue/shard';
8
+ import type { SqliteStorage } from '../../infrastructure/persistence/sqlite';
9
+ import { RWLock } from '../../shared/lock';
10
+ /** Ack operation context */
11
+ export interface AckContext {
12
+ storage: SqliteStorage | null;
13
+ shards: Shard[];
14
+ shardLocks: RWLock[];
15
+ processingShards: Map<JobId, Job>[];
16
+ processingLocks: RWLock[];
17
+ completedJobs: Set<JobId>;
18
+ jobResults: Map<JobId, unknown>;
19
+ jobIndex: Map<JobId, JobLocation>;
20
+ totalCompleted: {
21
+ value: bigint;
22
+ };
23
+ totalFailed: {
24
+ value: bigint;
25
+ };
26
+ broadcast: (event: {
27
+ eventType: EventType;
28
+ queue: string;
29
+ jobId: JobId;
30
+ timestamp: number;
31
+ data?: unknown;
32
+ error?: string;
33
+ }) => void;
34
+ onJobCompleted: (jobId: JobId) => void;
35
+ }
36
+ /**
37
+ * Acknowledge job completion
38
+ */
39
+ export declare function ackJob(jobId: JobId, result: unknown, ctx: AckContext): Promise<void>;
40
+ /**
41
+ * Mark job as failed
42
+ */
43
+ export declare function failJob(jobId: JobId, error: string | undefined, ctx: AckContext): Promise<void>;
44
+ /**
45
+ * Acknowledge multiple jobs
46
+ */
47
+ export declare function ackJobBatch(jobIds: JobId[], ctx: AckContext): Promise<void>;
48
+ //# sourceMappingURL=ack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ack.d.ts","sourceRoot":"","sources":["../../../src/application/operations/ack.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,KAAK,EAA8B,MAAM,wBAAwB,CAAC;AAC1F,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAiB,MAAM,mBAAmB,CAAC;AAG1D,4BAA4B;AAC5B,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC;IAC9B,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,gBAAgB,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;IACpC,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;IAC1B,UAAU,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAChC,QAAQ,EAAE,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAClC,cAAc,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,WAAW,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/B,SAAS,EAAE,CAAC,KAAK,EAAE;QACjB,SAAS,EAAE,SAAS,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,KAAK,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,KAAK,IAAI,CAAC;IACX,cAAc,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACxC;AAED;;GAEG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAgD1F;AAED;;GAEG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,GAAG,EAAE,UAAU,GACd,OAAO,CAAC,IAAI,CAAC,CA+Cf;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAIjF"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Ack/Fail Operations
3
+ * Job acknowledgement and failure handling
4
+ */
5
+ import { calculateBackoff, canRetry } from '../../domain/types/job';
6
+ import { withWriteLock } from '../../shared/lock';
7
+ import { shardIndex, processingShardIndex } from '../../shared/hash';
8
+ /**
9
+ * Acknowledge job completion
10
+ */
11
+ export async function ackJob(jobId, result, ctx) {
12
+ const procIdx = processingShardIndex(jobId);
13
+ // Remove from processing
14
+ const job = await withWriteLock(ctx.processingLocks[procIdx], () => {
15
+ const job = ctx.processingShards[procIdx].get(jobId);
16
+ if (job) {
17
+ ctx.processingShards[procIdx].delete(jobId);
18
+ }
19
+ return job;
20
+ });
21
+ if (!job) {
22
+ throw new Error('Job not found');
23
+ }
24
+ // Release resources
25
+ const idx = shardIndex(job.queue);
26
+ await withWriteLock(ctx.shardLocks[idx], () => {
27
+ ctx.shards[idx].releaseJobResources(job.queue, job.uniqueKey, job.groupId);
28
+ });
29
+ // Store result and mark completed
30
+ if (!job.removeOnComplete) {
31
+ ctx.completedJobs.add(jobId);
32
+ if (result !== undefined) {
33
+ ctx.jobResults.set(jobId, result);
34
+ ctx.storage?.storeResult(jobId, result);
35
+ }
36
+ ctx.jobIndex.set(jobId, { type: 'completed' });
37
+ ctx.storage?.markCompleted(jobId, Date.now());
38
+ }
39
+ else {
40
+ ctx.jobIndex.delete(jobId);
41
+ ctx.storage?.deleteJob(jobId);
42
+ }
43
+ // Update metrics
44
+ ctx.totalCompleted.value++;
45
+ ctx.broadcast({
46
+ eventType: 'completed',
47
+ queue: job.queue,
48
+ jobId,
49
+ timestamp: Date.now(),
50
+ data: result,
51
+ });
52
+ // Notify completion (for dependencies and parent jobs)
53
+ ctx.onJobCompleted(jobId);
54
+ }
55
+ /**
56
+ * Mark job as failed
57
+ */
58
+ export async function failJob(jobId, error, ctx) {
59
+ const procIdx = processingShardIndex(jobId);
60
+ // Remove from processing
61
+ const job = await withWriteLock(ctx.processingLocks[procIdx], () => {
62
+ const job = ctx.processingShards[procIdx].get(jobId);
63
+ if (job) {
64
+ ctx.processingShards[procIdx].delete(jobId);
65
+ }
66
+ return job;
67
+ });
68
+ if (!job) {
69
+ throw new Error('Job not found');
70
+ }
71
+ // Increment attempts
72
+ job.attempts++;
73
+ const idx = shardIndex(job.queue);
74
+ await withWriteLock(ctx.shardLocks[idx], () => {
75
+ const shard = ctx.shards[idx];
76
+ shard.releaseJobResources(job.queue, job.uniqueKey, job.groupId);
77
+ if (canRetry(job)) {
78
+ // Retry with exponential backoff
79
+ job.runAt = Date.now() + calculateBackoff(job);
80
+ shard.getQueue(job.queue).push(job);
81
+ ctx.jobIndex.set(jobId, { type: 'queue', shardIdx: idx, queueName: job.queue });
82
+ ctx.storage?.updateForRetry(job);
83
+ }
84
+ else {
85
+ // Move to DLQ
86
+ shard.addToDlq(job);
87
+ ctx.jobIndex.set(jobId, { type: 'dlq', queueName: job.queue });
88
+ ctx.storage?.markFailed(job, error ?? null);
89
+ ctx.totalFailed.value++;
90
+ }
91
+ });
92
+ // Broadcast event
93
+ ctx.broadcast({
94
+ eventType: 'failed',
95
+ queue: job.queue,
96
+ jobId,
97
+ timestamp: Date.now(),
98
+ error,
99
+ });
100
+ }
101
+ /**
102
+ * Acknowledge multiple jobs
103
+ */
104
+ export async function ackJobBatch(jobIds, ctx) {
105
+ for (const id of jobIds) {
106
+ await ackJob(id, undefined, ctx);
107
+ }
108
+ }
109
+ //# sourceMappingURL=ack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ack.js","sourceRoot":"","sources":["../../../src/application/operations/ack.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAwB,gBAAgB,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAI1F,OAAO,EAAU,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAyBrE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,KAAY,EAAE,MAAe,EAAE,GAAe;IACzE,MAAM,OAAO,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;IAE5C,yBAAyB;IACzB,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE;QACjE,MAAM,GAAG,GAAG,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrD,IAAI,GAAG,EAAE,CAAC;YACR,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED,oBAAoB;IACpB,MAAM,GAAG,GAAG,UAAU,CAAC,GAAG,CA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AC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACpC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;YAChF,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;aAAM,CAAC;YACN,cAAc;YACd,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YACpB,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;YAC/D,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC;YAC5C,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,kBAAkB;IAClB,GAAG,CAAC,SAAS,CAAC;QACZ,SAAS,EAAE,QAAqB;QAChC,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,KAAK;QACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,KAAK;KACN,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAe,EAAE,GAAe;IAChE,KAAK,MAAM,EAAE,IAAI,MAAM,EAAE,CAAC;QACxB,MAAM,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Operations barrel export
3
+ */
4
+ export * from './push';
5
+ export * from './pull';
6
+ export * from './ack';
7
+ export * from './queueControl';
8
+ export * from './jobManagement';
9
+ export * from './queryOperations';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/application/operations/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Operations barrel export
3
+ */
4
+ export * from './push';
5
+ export * from './pull';
6
+ export * from './ack';
7
+ export * from './queueControl';
8
+ export * from './jobManagement';
9
+ export * from './queryOperations';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/application/operations/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Job Management Operations
3
+ * Cancel, update progress, change priority, promote, move to delayed, discard
4
+ */
5
+ import type { Job, JobId } from '../../domain/types/job';
6
+ import type { JobLocation } from '../../domain/types/queue';
7
+ import type { Shard } from '../../domain/queue/shard';
8
+ import type { SqliteStorage } from '../../infrastructure/persistence/sqlite';
9
+ import type { WebhookManager } from '../webhookManager';
10
+ /** Context for job management operations */
11
+ export interface JobManagementContext {
12
+ storage: SqliteStorage | null;
13
+ shards: Shard[];
14
+ processingShards: Map<JobId, Job>[];
15
+ jobIndex: Map<JobId, JobLocation>;
16
+ webhookManager: WebhookManager;
17
+ }
18
+ /** Cancel a job (remove from queue) */
19
+ export declare function cancelJob(jobId: JobId, ctx: JobManagementContext): Promise<boolean>;
20
+ /** Update job progress */
21
+ export declare function updateJobProgress(jobId: JobId, progress: number, ctx: JobManagementContext, message?: string): Promise<boolean>;
22
+ /** Update job data */
23
+ export declare function updateJobData(jobId: JobId, data: unknown, ctx: JobManagementContext): Promise<boolean>;
24
+ /** Change job priority */
25
+ export declare function changeJobPriority(jobId: JobId, priority: number, ctx: JobManagementContext): Promise<boolean>;
26
+ /** Promote delayed job to waiting */
27
+ export declare function promoteJob(jobId: JobId, ctx: JobManagementContext): Promise<boolean>;
28
+ /** Move active job back to delayed */
29
+ export declare function moveJobToDelayed(jobId: JobId, delay: number, ctx: JobManagementContext): Promise<boolean>;
30
+ /** Discard job to DLQ */
31
+ export declare function discardJob(jobId: JobId, ctx: JobManagementContext): Promise<boolean>;
32
+ //# sourceMappingURL=jobManagement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jobManagement.d.ts","sourceRoot":"","sources":["../../../src/application/operations/jobManagement.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,4CAA4C;AAC5C,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC;IAC9B,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,gBAAgB,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;IACpC,QAAQ,EAAE,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;CAChC;AAED,uCAAuC;AACvC,wBAAsB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,oBAAoB,GAA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