bunqueue 2.6.90 → 2.6.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/bunqueue/aging.d.ts +16 -0
- package/dist/client/bunqueue/aging.d.ts.map +1 -0
- package/dist/client/bunqueue/aging.js +53 -0
- package/dist/client/bunqueue/aging.js.map +1 -0
- package/dist/client/bunqueue/batch.d.ts +17 -0
- package/dist/client/bunqueue/batch.d.ts.map +1 -0
- package/dist/client/bunqueue/batch.js +60 -0
- package/dist/client/bunqueue/batch.js.map +1 -0
- package/dist/client/bunqueue/cancellation.d.ts +20 -0
- package/dist/client/bunqueue/cancellation.d.ts.map +1 -0
- package/dist/client/bunqueue/cancellation.js +48 -0
- package/dist/client/bunqueue/cancellation.js.map +1 -0
- package/dist/client/bunqueue/circuitBreaker.d.ts +21 -0
- package/dist/client/bunqueue/circuitBreaker.d.ts.map +1 -0
- package/dist/client/bunqueue/circuitBreaker.js +68 -0
- package/dist/client/bunqueue/circuitBreaker.js.map +1 -0
- package/dist/client/bunqueue/retry.d.ts +9 -0
- package/dist/client/bunqueue/retry.d.ts.map +1 -0
- package/dist/client/bunqueue/retry.js +55 -0
- package/dist/client/bunqueue/retry.js.map +1 -0
- package/dist/client/bunqueue/triggers.d.ts +18 -0
- package/dist/client/bunqueue/triggers.d.ts.map +1 -0
- package/dist/client/bunqueue/triggers.js +42 -0
- package/dist/client/bunqueue/triggers.js.map +1 -0
- package/dist/client/bunqueue/ttl.d.ts +18 -0
- package/dist/client/bunqueue/ttl.d.ts.map +1 -0
- package/dist/client/bunqueue/ttl.js +31 -0
- package/dist/client/bunqueue/ttl.js.map +1 -0
- package/dist/client/bunqueue/types.d.ts +106 -0
- package/dist/client/bunqueue/types.d.ts.map +1 -0
- package/dist/client/bunqueue/types.js +5 -0
- package/dist/client/bunqueue/types.js.map +1 -0
- package/dist/client/bunqueue.d.ts +27 -77
- package/dist/client/bunqueue.d.ts.map +1 -1
- package/dist/client/bunqueue.js +130 -97
- package/dist/client/bunqueue.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Priority Aging
|
|
3
|
+
* Automatically boosts priority of old waiting jobs.
|
|
4
|
+
*/
|
|
5
|
+
import type { Queue } from '../queue/queue';
|
|
6
|
+
import type { PriorityAgingConfig } from './types';
|
|
7
|
+
export declare class PriorityAger<T = unknown> {
|
|
8
|
+
private timer;
|
|
9
|
+
private readonly config;
|
|
10
|
+
private readonly queue;
|
|
11
|
+
constructor(config: PriorityAgingConfig, queue: Queue<T>);
|
|
12
|
+
start(): void;
|
|
13
|
+
private tick;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=aging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aging.d.ts","sourceRoot":"","sources":["../../../src/client/bunqueue/aging.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,qBAAa,YAAY,CAAC,CAAC,GAAG,OAAO;IACnC,OAAO,CAAC,KAAK,CAA+C;IAC5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAW;gBAErB,MAAM,EAAE,mBAAmB,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAKxD,KAAK,IAAI,IAAI;YAOC,IAAI;IA6BlB,OAAO,IAAI,IAAI;CAMhB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Priority Aging
|
|
3
|
+
* Automatically boosts priority of old waiting jobs.
|
|
4
|
+
*/
|
|
5
|
+
export class PriorityAger {
|
|
6
|
+
timer = null;
|
|
7
|
+
config;
|
|
8
|
+
queue;
|
|
9
|
+
constructor(config, queue) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.queue = queue;
|
|
12
|
+
}
|
|
13
|
+
start() {
|
|
14
|
+
const interval = this.config.interval ?? 60000;
|
|
15
|
+
this.timer = setInterval(() => {
|
|
16
|
+
void this.tick();
|
|
17
|
+
}, interval);
|
|
18
|
+
}
|
|
19
|
+
async tick() {
|
|
20
|
+
const minAge = this.config.minAge ?? 60000;
|
|
21
|
+
const boost = this.config.boost ?? 1;
|
|
22
|
+
const maxPriority = this.config.maxPriority ?? 100;
|
|
23
|
+
const maxScan = this.config.maxScan ?? 100;
|
|
24
|
+
// Get both waiting and prioritized jobs (jobs with priority > 0 are "prioritized")
|
|
25
|
+
const [waiting, prioritized] = await Promise.all([
|
|
26
|
+
this.queue.getWaitingAsync(0, maxScan),
|
|
27
|
+
this.queue.getJobsAsync({ state: 'prioritized', start: 0, end: maxScan }),
|
|
28
|
+
]);
|
|
29
|
+
const jobs = [...waiting, ...prioritized];
|
|
30
|
+
const now = Date.now();
|
|
31
|
+
for (const job of jobs) {
|
|
32
|
+
const age = now - job.timestamp;
|
|
33
|
+
if (age >= minAge && job.priority < maxPriority) {
|
|
34
|
+
const newPriority = Math.min(job.priority + boost, maxPriority);
|
|
35
|
+
try {
|
|
36
|
+
await this.queue.changeJobPriority(job.id, {
|
|
37
|
+
priority: newPriority,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Best-effort — job may have been processed
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
destroy() {
|
|
47
|
+
if (this.timer) {
|
|
48
|
+
clearInterval(this.timer);
|
|
49
|
+
this.timer = null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=a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GAAG,OAAO,EAAE,GAAG,WAAW,CAAC,CAAC;QAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAEvB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC;YAChC,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC,QAAQ,GAAG,WAAW,EAAE,CAAC;gBAChD,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,GAAG,KAAK,EAAE,WAAW,CAAC,CAAC;gBAChE,IAAI,CAAC;oBACH,MAAM,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,EAAE;wBACzC,QAAQ,EAAE,WAAW;qBACtB,CAAC,CAAC;gBACL,CAAC;gBAAC,MAAM,CAAC;oBACP,4CAA4C;gBAC9C,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Batch Processing
|
|
3
|
+
* Accumulates jobs and processes them in groups.
|
|
4
|
+
*/
|
|
5
|
+
import type { Processor } from '../types';
|
|
6
|
+
import type { BatchConfig } from './types';
|
|
7
|
+
export declare class BatchAccumulator<T = unknown, R = unknown> {
|
|
8
|
+
private readonly buffer;
|
|
9
|
+
private timer;
|
|
10
|
+
private readonly config;
|
|
11
|
+
constructor(config: BatchConfig<T, R>);
|
|
12
|
+
/** Build a Processor that buffers jobs into batches */
|
|
13
|
+
buildProcessor(): Processor<T, R>;
|
|
14
|
+
flush(): void;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../../src/client/bunqueue/batch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAoB,SAAS,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAQ3C,qBAAa,gBAAgB,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO;IACpD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2B;IAClD,OAAO,CAAC,KAAK,CAA8C;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;gBAE/B,MAAM,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;IAIrC,uDAAuD;IACvD,cAAc,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;IAiBjC,KAAK,IAAI,IAAI;IAyBb,OAAO,IAAI,IAAI;CAUhB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Batch Processing
|
|
3
|
+
* Accumulates jobs and processes them in groups.
|
|
4
|
+
*/
|
|
5
|
+
export class BatchAccumulator {
|
|
6
|
+
buffer = [];
|
|
7
|
+
timer = null;
|
|
8
|
+
config;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
}
|
|
12
|
+
/** Build a Processor that buffers jobs into batches */
|
|
13
|
+
buildProcessor() {
|
|
14
|
+
return ((job) => {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
this.buffer.push({ job, resolve, reject });
|
|
17
|
+
if (this.buffer.length >= this.config.size) {
|
|
18
|
+
this.flush();
|
|
19
|
+
}
|
|
20
|
+
else if (!this.timer) {
|
|
21
|
+
const timeout = this.config.timeout ?? 5000;
|
|
22
|
+
this.timer = setTimeout(() => {
|
|
23
|
+
this.flush();
|
|
24
|
+
}, timeout);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
flush() {
|
|
30
|
+
if (this.timer) {
|
|
31
|
+
clearTimeout(this.timer);
|
|
32
|
+
this.timer = null;
|
|
33
|
+
}
|
|
34
|
+
const batch = this.buffer.splice(0);
|
|
35
|
+
if (batch.length === 0)
|
|
36
|
+
return;
|
|
37
|
+
const jobs = batch.map((b) => b.job);
|
|
38
|
+
this.config.processor(jobs).then((results) => {
|
|
39
|
+
for (let i = 0; i < batch.length; i++) {
|
|
40
|
+
batch[i].resolve(results[i] ?? undefined);
|
|
41
|
+
}
|
|
42
|
+
}, (err) => {
|
|
43
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
44
|
+
for (const b of batch) {
|
|
45
|
+
b.reject(error);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
destroy() {
|
|
50
|
+
if (this.timer) {
|
|
51
|
+
clearTimeout(this.timer);
|
|
52
|
+
this.timer = null;
|
|
53
|
+
}
|
|
54
|
+
// Flush remaining
|
|
55
|
+
if (this.buffer.length > 0) {
|
|
56
|
+
this.flush();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.js","sourceRoot":"","sources":["../../../src/client/bunqueue/batch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,MAAM,OAAO,gBAAgB;IACV,MAAM,GAAwB,EAAE,CAAC;IAC1C,KAAK,GAAyC,IAAI,CAAC;IAC1C,MAAM,CAAoB;IAE3C,YAAY,MAAyB;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,uDAAuD;IACvD,cAAc;QACZ,OAAO,CAAC,CAAC,GAAyB,EAAc,EAAE;YAChD,OAAO,IAAI,OAAO,C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CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAK,SAA0B,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC,EACD,CAAC,GAAY,EAAE,EAAE;YACf,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAClE,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;gBACtB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;QACD,kBAAkB;QAClB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3B,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Graceful Job Cancellation
|
|
3
|
+
* AbortController-based cancellation with optional grace period.
|
|
4
|
+
*/
|
|
5
|
+
export declare class CancellationManager {
|
|
6
|
+
private readonly controllers;
|
|
7
|
+
/** Register a new AbortController for a job */
|
|
8
|
+
register(jobId: string): AbortController;
|
|
9
|
+
/** Remove a job's controller (on completion) */
|
|
10
|
+
unregister(jobId: string): void;
|
|
11
|
+
/** Cancel a job with optional grace period */
|
|
12
|
+
cancel(jobId: string, gracePeriodMs?: number): void;
|
|
13
|
+
/** Check if a job is cancelled */
|
|
14
|
+
isCancelled(jobId: string): boolean;
|
|
15
|
+
/** Get the AbortSignal for a job */
|
|
16
|
+
getSignal(jobId: string): AbortSignal | null;
|
|
17
|
+
/** Cancel all and clear */
|
|
18
|
+
destroyAll(): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=cancellation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancellation.d.ts","sourceRoot":"","sources":["../../../src/client/bunqueue/cancellation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsC;IAElE,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe;IAMxC,gDAAgD;IAChD,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI/B,8CAA8C;IAC9C,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,SAAI,GAAG,IAAI;IAa9C,kCAAkC;IAClC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAKnC,oCAAoC;IACpC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAI5C,2BAA2B;IAC3B,UAAU,IAAI,IAAI;CAMnB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Graceful Job Cancellation
|
|
3
|
+
* AbortController-based cancellation with optional grace period.
|
|
4
|
+
*/
|
|
5
|
+
export class CancellationManager {
|
|
6
|
+
controllers = new Map();
|
|
7
|
+
/** Register a new AbortController for a job */
|
|
8
|
+
register(jobId) {
|
|
9
|
+
const ac = new AbortController();
|
|
10
|
+
this.controllers.set(jobId, ac);
|
|
11
|
+
return ac;
|
|
12
|
+
}
|
|
13
|
+
/** Remove a job's controller (on completion) */
|
|
14
|
+
unregister(jobId) {
|
|
15
|
+
this.controllers.delete(jobId);
|
|
16
|
+
}
|
|
17
|
+
/** Cancel a job with optional grace period */
|
|
18
|
+
cancel(jobId, gracePeriodMs = 0) {
|
|
19
|
+
const ac = this.controllers.get(jobId);
|
|
20
|
+
if (!ac)
|
|
21
|
+
return;
|
|
22
|
+
if (gracePeriodMs > 0) {
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
ac.abort();
|
|
25
|
+
}, gracePeriodMs);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
ac.abort();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Check if a job is cancelled */
|
|
32
|
+
isCancelled(jobId) {
|
|
33
|
+
const ac = this.controllers.get(jobId);
|
|
34
|
+
return ac ? ac.signal.aborted : false;
|
|
35
|
+
}
|
|
36
|
+
/** Get the AbortSignal for a job */
|
|
37
|
+
getSignal(jobId) {
|
|
38
|
+
return this.controllers.get(jobId)?.signal ?? null;
|
|
39
|
+
}
|
|
40
|
+
/** Cancel all and clear */
|
|
41
|
+
destroyAll() {
|
|
42
|
+
for (const ac of this.controllers.values()) {
|
|
43
|
+
ac.abort();
|
|
44
|
+
}
|
|
45
|
+
this.controllers.clear();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=cancellation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancellation.js","sourceRoot":"","sources":["../../../src/client/bunqueue/cancellation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,OAAO,mBAAmB;IACb,WAAW,GAAG,IAAI,GAAG,EAA2B,CAAC;IAElE,+CAA+C;IAC/C,QAAQ,CAAC,KAAa;QACpB,MAAM,EAAE,GAAG,IAAI,eAAe,EAAE,CAAC;QACjC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAChC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,gDAAgD;IAChD,UAAU,CAAC,KAAa;QACtB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,8CAA8C;IAC9C,MAAM,CAAC,KAAa,EAAE,aAAa,GAAG,CAAC;QACrC,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,CAAC,EAAE;YAAE,OAAO;QAEhB,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;YACtB,UAAU,CAAC,GAAG,EAAE;gBACd,EAAE,CAAC,KAAK,EAAE,CAAC;YACb,CAAC,EAAE,aAAa,CAAC,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,KAAK,EAAE,CAAC;QACb,CAAC;IACH,CAAC;IAED,kCAAkC;IAClC,WAAW,CAAC,KAAa;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACvC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IACxC,CAAC;IAED,oCAAoC;IACpC,SAAS,CAAC,KAAa;QACrB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,IAAI,IAAI,CAAC;IACrD,CAAC;IAED,2BAA2B;IAC3B,UAAU;QACR,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3C,EAAE,CAAC,KAAK,EAAE,CAAC;QACb,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Circuit Breaker for worker protection
|
|
3
|
+
*/
|
|
4
|
+
import type { Worker } from '../worker/worker';
|
|
5
|
+
import type { CircuitBreakerConfig, CircuitState } from './types';
|
|
6
|
+
export declare class WorkerCircuitBreaker {
|
|
7
|
+
private state;
|
|
8
|
+
private failures;
|
|
9
|
+
private timer;
|
|
10
|
+
private readonly config;
|
|
11
|
+
private readonly worker;
|
|
12
|
+
constructor(config: CircuitBreakerConfig, worker: Worker);
|
|
13
|
+
get currentState(): CircuitState;
|
|
14
|
+
isOpen(): boolean;
|
|
15
|
+
onSuccess(): void;
|
|
16
|
+
onFailure(): void;
|
|
17
|
+
private open;
|
|
18
|
+
reset(): void;
|
|
19
|
+
destroy(): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=circuitBreaker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuitBreaker.d.ts","sourceRoot":"","sources":["../../../src/client/bunqueue/circuitBreaker.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAElE,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,KAAK,CAA8C;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM;IAKxD,IAAI,YAAY,IAAI,YAAY,CAE/B;IAED,MAAM,IAAI,OAAO;IAIjB,SAAS,IAAI,IAAI;IAUjB,SAAS,IAAI,IAAI;IASjB,OAAO,CAAC,IAAI;IAcZ,KAAK,IAAI,IAAI;IAYb,OAAO,IAAI,IAAI;CAMhB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Circuit Breaker for worker protection
|
|
3
|
+
*/
|
|
4
|
+
export class WorkerCircuitBreaker {
|
|
5
|
+
state = 'closed';
|
|
6
|
+
failures = 0;
|
|
7
|
+
timer = null;
|
|
8
|
+
config;
|
|
9
|
+
worker;
|
|
10
|
+
constructor(config, worker) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.worker = worker;
|
|
13
|
+
}
|
|
14
|
+
get currentState() {
|
|
15
|
+
return this.state;
|
|
16
|
+
}
|
|
17
|
+
isOpen() {
|
|
18
|
+
return this.state === 'open';
|
|
19
|
+
}
|
|
20
|
+
onSuccess() {
|
|
21
|
+
if (this.state === 'half-open') {
|
|
22
|
+
this.state = 'closed';
|
|
23
|
+
this.failures = 0;
|
|
24
|
+
this.config.onClose?.();
|
|
25
|
+
}
|
|
26
|
+
else if (this.state === 'closed') {
|
|
27
|
+
this.failures = 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
onFailure() {
|
|
31
|
+
this.failures++;
|
|
32
|
+
const threshold = this.config.threshold ?? 5;
|
|
33
|
+
if (this.state === 'half-open' || this.failures >= threshold) {
|
|
34
|
+
this.open();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
open() {
|
|
38
|
+
this.state = 'open';
|
|
39
|
+
this.config.onOpen?.(this.failures);
|
|
40
|
+
this.worker.pause();
|
|
41
|
+
const resetTimeout = this.config.resetTimeout ?? 30000;
|
|
42
|
+
if (this.timer)
|
|
43
|
+
clearTimeout(this.timer);
|
|
44
|
+
this.timer = setTimeout(() => {
|
|
45
|
+
this.state = 'half-open';
|
|
46
|
+
this.config.onHalfOpen?.();
|
|
47
|
+
this.worker.resume();
|
|
48
|
+
}, resetTimeout);
|
|
49
|
+
}
|
|
50
|
+
reset() {
|
|
51
|
+
this.state = 'closed';
|
|
52
|
+
this.failures = 0;
|
|
53
|
+
if (this.timer) {
|
|
54
|
+
clearTimeout(this.timer);
|
|
55
|
+
this.timer = null;
|
|
56
|
+
}
|
|
57
|
+
if (this.worker.isPaused()) {
|
|
58
|
+
this.worker.resume();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
destroy() {
|
|
62
|
+
if (this.timer) {
|
|
63
|
+
clearTimeout(this.timer);
|
|
64
|
+
this.timer = null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=circuitBreaker.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,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAEpB,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,KAAK,CAAC;QACvD,IAAI,IAAI,CAAC,KAAK;YAAE,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC3B,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC;YACzB,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC,EAAE,YAAY,CAAC,CAAC;IACnB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAClB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Advanced Retry with backoff strategies
|
|
3
|
+
*/
|
|
4
|
+
import type { RetryConfig, RetryStrategy } from './types';
|
|
5
|
+
/** Calculate backoff delay based on strategy */
|
|
6
|
+
export declare function calculateBackoff(strategy: RetryStrategy, attempt: number, baseDelay: number, error: Error, config: RetryConfig): number;
|
|
7
|
+
/** Execute a function with retry logic */
|
|
8
|
+
export declare function executeWithRetry<R>(fn: () => Promise<R>, config: RetryConfig): Promise<R>;
|
|
9
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/client/bunqueue/retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE1D,gDAAgD;AAChD,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,WAAW,GAClB,MAAM,CAiCR;AAED,0CAA0C;AAC1C,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAqBzF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Advanced Retry with backoff strategies
|
|
3
|
+
*/
|
|
4
|
+
/** Calculate backoff delay based on strategy */
|
|
5
|
+
export function calculateBackoff(strategy, attempt, baseDelay, error, config) {
|
|
6
|
+
switch (strategy) {
|
|
7
|
+
case 'fixed':
|
|
8
|
+
return baseDelay;
|
|
9
|
+
case 'exponential':
|
|
10
|
+
return baseDelay * Math.pow(2, attempt - 1);
|
|
11
|
+
case 'jitter': {
|
|
12
|
+
const exp = baseDelay * Math.pow(2, attempt - 1);
|
|
13
|
+
return Math.floor(exp * (0.5 + Math.random()));
|
|
14
|
+
}
|
|
15
|
+
case 'fibonacci': {
|
|
16
|
+
let a = 1, b = 1;
|
|
17
|
+
for (let i = 0; i < attempt - 1; i++) {
|
|
18
|
+
const next = a + b;
|
|
19
|
+
a = b;
|
|
20
|
+
b = next;
|
|
21
|
+
}
|
|
22
|
+
return baseDelay * b;
|
|
23
|
+
}
|
|
24
|
+
case 'custom':
|
|
25
|
+
if (config.customBackoff) {
|
|
26
|
+
return config.customBackoff(attempt, error);
|
|
27
|
+
}
|
|
28
|
+
return baseDelay;
|
|
29
|
+
default:
|
|
30
|
+
return baseDelay;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Execute a function with retry logic */
|
|
34
|
+
export function executeWithRetry(fn, config) {
|
|
35
|
+
const maxAttempts = config.maxAttempts ?? 3;
|
|
36
|
+
const baseDelay = config.delay ?? 1000;
|
|
37
|
+
const strategy = config.strategy ?? 'exponential';
|
|
38
|
+
const attempt = (n) => {
|
|
39
|
+
return fn().catch((err) => {
|
|
40
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
41
|
+
if (n >= maxAttempts)
|
|
42
|
+
throw error;
|
|
43
|
+
if (config.retryIf && !config.retryIf(error, n))
|
|
44
|
+
throw error;
|
|
45
|
+
const delay = calculateBackoff(strategy, n, baseDelay, error, config);
|
|
46
|
+
return new Promise((resolve) => {
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
resolve(attempt(n + 1));
|
|
49
|
+
}, delay);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
return attempt(1);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../../src/client/bunqueue/retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,gDAAgD;AAChD,MAAM,UAAU,gBAAgB,CAC9B,QAAuB,EACvB,OAAe,EACf,SAAiB,EACjB,KAAY,EACZ,MAAmB;IAEnB,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,OAAO;YACV,OA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O,GAAG,CAAC,CAAS,EAAc,EAAE;QACxC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;YACjC,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAClE,IAAI,CAAC,IAAI,WAAW;gBAAE,MAAM,KAAK,CAAC;YAClC,IAAI,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;gBAAE,MAAM,KAAK,CAAC;YAE7D,MAAM,KAAK,GAAG,gBAAgB,CAAC,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;YACtE,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,EAAE;gBAChC,UAAU,CAAC,GAAG,EAAE;oBACd,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC1B,CAAC,EAAE,KAAK,CAAC,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Event Triggers
|
|
3
|
+
* When a job completes/fails, automatically create another job.
|
|
4
|
+
*/
|
|
5
|
+
import type { Queue } from '../queue/queue';
|
|
6
|
+
import type { Worker } from '../worker/worker';
|
|
7
|
+
import type { TriggerRule } from './types';
|
|
8
|
+
export declare class TriggerManager<T = unknown, R = unknown> {
|
|
9
|
+
private readonly rules;
|
|
10
|
+
private active;
|
|
11
|
+
private readonly queue;
|
|
12
|
+
private readonly worker;
|
|
13
|
+
constructor(queue: Queue<T>, worker: Worker<T, R>);
|
|
14
|
+
add(rule: TriggerRule<T>): void;
|
|
15
|
+
private ensureActive;
|
|
16
|
+
private fire;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=triggers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triggers.d.ts","sourceRoot":"","sources":["../../../src/client/bunqueue/triggers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,qBAAa,cAAc,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO;IAClD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAwB;IAC9C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAW;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;gBAE1B,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAKjD,GAAG,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI;IAK/B,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,IAAI;CAUb"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Event Triggers
|
|
3
|
+
* When a job completes/fails, automatically create another job.
|
|
4
|
+
*/
|
|
5
|
+
export class TriggerManager {
|
|
6
|
+
rules = [];
|
|
7
|
+
active = false;
|
|
8
|
+
queue;
|
|
9
|
+
worker;
|
|
10
|
+
constructor(queue, worker) {
|
|
11
|
+
this.queue = queue;
|
|
12
|
+
this.worker = worker;
|
|
13
|
+
}
|
|
14
|
+
add(rule) {
|
|
15
|
+
this.rules.push(rule);
|
|
16
|
+
this.ensureActive();
|
|
17
|
+
}
|
|
18
|
+
ensureActive() {
|
|
19
|
+
if (this.active)
|
|
20
|
+
return;
|
|
21
|
+
this.active = true;
|
|
22
|
+
this.worker.on('completed', (job, result) => {
|
|
23
|
+
this.fire('completed', job, result);
|
|
24
|
+
});
|
|
25
|
+
this.worker.on('failed', (job, error) => {
|
|
26
|
+
this.fire('failed', job, error);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
fire(event, job, resultOrError) {
|
|
30
|
+
for (const rule of this.rules) {
|
|
31
|
+
if (rule.on !== job.name)
|
|
32
|
+
continue;
|
|
33
|
+
if ((rule.event ?? 'completed') !== event)
|
|
34
|
+
continue;
|
|
35
|
+
if (rule.condition && !rule.condition(resultOrError, job))
|
|
36
|
+
continue;
|
|
37
|
+
const data = rule.data(resultOrError, job);
|
|
38
|
+
void this.queue.add(rule.create, data, rule.opts);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=triggers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triggers.js","sourceRoot":"","sources":["../../../src/client/bunqueue/triggers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,MAAM,OAAO,cAAc;IACR,KAAK,GAAqB,EAAE,CAAC;IACtC,MAAM,GAAG,KAAK,CAAC;IACN,KAAK,CAAW;IAChB,MAAM,CAAe;IAEtC,YAAY,KAAe,EAAE,MAAoB;QAC/C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,GAAG,CAAC,IAAoB;QACtB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAEO,YAAY;QAClB,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QAEnB,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,GAAW,EAAE,MAAS,EAAE,EAAE;YACrD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAW,EAAE,KAAY,EAAE,EAAE;YACrD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,IAAI,CAAC,KAA6B,EAAE,GAAW,EAAE,aAAsB;QAC7E,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,IAAI,IAAI,CAAC,EAAE,KAAK,GAAG,CAAC,IAAI;gBAAE,SAAS;YACnC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,KAAK;gBAAE,SAAS;YACpD,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,GAAG,CAAC;gBAAE,SAAS;YAEpE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;YAC3C,KAAK,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Job TTL (Time To Live)
|
|
3
|
+
* Expire unprocessed jobs based on configurable TTL.
|
|
4
|
+
*/
|
|
5
|
+
import type { JobTtlConfig } from './types';
|
|
6
|
+
export declare class TtlChecker {
|
|
7
|
+
private readonly config;
|
|
8
|
+
constructor(config: JobTtlConfig);
|
|
9
|
+
/** Get TTL for a specific job name */
|
|
10
|
+
getTtl(jobName: string): number;
|
|
11
|
+
/** Check if a job has expired */
|
|
12
|
+
isExpired(jobName: string, jobTimestamp: number): boolean;
|
|
13
|
+
/** Set default TTL */
|
|
14
|
+
setDefaultTtl(ttlMs: number): void;
|
|
15
|
+
/** Set TTL for a specific job name */
|
|
16
|
+
setNameTtl(jobName: string, ttlMs: number): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ttl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ttl.d.ts","sourceRoot":"","sources":["../../../src/client/bunqueue/ttl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;gBAE1B,MAAM,EAAE,YAAY;IAIhC,sCAAsC;IACtC,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAI/B,iCAAiC;IACjC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO;IAMzD,sBAAsB;IACtB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIlC,sCAAsC;IACtC,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAIjD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue — Job TTL (Time To Live)
|
|
3
|
+
* Expire unprocessed jobs based on configurable TTL.
|
|
4
|
+
*/
|
|
5
|
+
export class TtlChecker {
|
|
6
|
+
config;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
}
|
|
10
|
+
/** Get TTL for a specific job name */
|
|
11
|
+
getTtl(jobName) {
|
|
12
|
+
return this.config.perName?.[jobName] ?? this.config.defaultTtl ?? 0;
|
|
13
|
+
}
|
|
14
|
+
/** Check if a job has expired */
|
|
15
|
+
isExpired(jobName, jobTimestamp) {
|
|
16
|
+
const ttl = this.getTtl(jobName);
|
|
17
|
+
if (ttl <= 0)
|
|
18
|
+
return false;
|
|
19
|
+
return Date.now() - jobTimestamp > ttl;
|
|
20
|
+
}
|
|
21
|
+
/** Set default TTL */
|
|
22
|
+
setDefaultTtl(ttlMs) {
|
|
23
|
+
this.config.defaultTtl = ttlMs;
|
|
24
|
+
}
|
|
25
|
+
/** Set TTL for a specific job name */
|
|
26
|
+
setNameTtl(jobName, ttlMs) {
|
|
27
|
+
this.config.perName ??= {};
|
|
28
|
+
this.config.perName[jobName] = ttlMs;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=ttl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ttl.js","sourceRoot":"","sources":["../../../src/client/bunqueue/ttl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,OAAO,UAAU;IACJ,MAAM,CAAe;IAEtC,YAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,sCAAsC;IACtC,MAAM,CAAC,OAAe;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC;IACvE,CAAC;IAED,iCAAiC;IACjC,SAAS,CAAC,OAAe,EAAE,YAAoB;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACjC,IAAI,GAAG,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QAC3B,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,YAAY,GAAG,GAAG,CAAC;IACzC,CAAC;IAED,sBAAsB;IACtB,aAAa,CAAC,KAAa;QACzB,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,KAAK,CAAC;IACjC,CAAC;IAED,sCAAsC;IACtC,UAAU,CAAC,OAAe,EAAE,KAAa;QACvC,IAAI,CAAC,MAAM,CAAC,OAAO,KAAK,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunqueue Simple Mode — Type definitions
|
|
3
|
+
*/
|
|
4
|
+
import type { Job, JobOptions, Processor, ConnectionOptions, QueueOptions, WorkerOptions } from '../types';
|
|
5
|
+
/** Middleware function: receives job and next(), returns result */
|
|
6
|
+
export type BunqueueMiddleware<T = unknown, R = unknown> = (job: Job<T>, next: () => Promise<R>) => Promise<R>;
|
|
7
|
+
/** Retry strategy for advanced backoff */
|
|
8
|
+
export type RetryStrategy = 'fixed' | 'exponential' | 'jitter' | 'fibonacci' | 'custom';
|
|
9
|
+
/** Advanced retry configuration */
|
|
10
|
+
export interface RetryConfig {
|
|
11
|
+
/** Max attempts (default: 3) */
|
|
12
|
+
maxAttempts?: number;
|
|
13
|
+
/** Base delay in ms (default: 1000) */
|
|
14
|
+
delay?: number;
|
|
15
|
+
/** Strategy (default: exponential) */
|
|
16
|
+
strategy?: RetryStrategy;
|
|
17
|
+
/** Custom backoff function: attempt → delay in ms */
|
|
18
|
+
customBackoff?: (attempt: number, error: Error) => number;
|
|
19
|
+
/** Only retry if this returns true */
|
|
20
|
+
retryIf?: (error: Error, attempt: number) => boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Circuit breaker configuration */
|
|
23
|
+
export interface CircuitBreakerConfig {
|
|
24
|
+
/** Max consecutive failures before opening (default: 5) */
|
|
25
|
+
threshold?: number;
|
|
26
|
+
/** Time in ms before half-open retry (default: 30000) */
|
|
27
|
+
resetTimeout?: number;
|
|
28
|
+
/** Callback when circuit opens */
|
|
29
|
+
onOpen?: (failures: number) => void;
|
|
30
|
+
/** Callback when circuit closes */
|
|
31
|
+
onClose?: () => void;
|
|
32
|
+
/** Callback on half-open probe */
|
|
33
|
+
onHalfOpen?: () => void;
|
|
34
|
+
}
|
|
35
|
+
/** Circuit breaker state */
|
|
36
|
+
export type CircuitState = 'closed' | 'open' | 'half-open';
|
|
37
|
+
/** Event trigger rule */
|
|
38
|
+
export interface TriggerRule<T = unknown> {
|
|
39
|
+
/** Job name that triggers this rule */
|
|
40
|
+
on: string;
|
|
41
|
+
/** Event type (default: completed) */
|
|
42
|
+
event?: 'completed' | 'failed';
|
|
43
|
+
/** Job name to create */
|
|
44
|
+
create: string;
|
|
45
|
+
/** Data builder from the triggering job */
|
|
46
|
+
data: (result: unknown, job: Job<T>) => T;
|
|
47
|
+
/** Optional job options */
|
|
48
|
+
opts?: JobOptions;
|
|
49
|
+
/** Optional condition */
|
|
50
|
+
condition?: (result: unknown, job: Job<T>) => boolean;
|
|
51
|
+
}
|
|
52
|
+
/** Priority aging configuration */
|
|
53
|
+
export interface PriorityAgingConfig {
|
|
54
|
+
/** Check interval in ms (default: 60000) */
|
|
55
|
+
interval?: number;
|
|
56
|
+
/** Min age in ms before boost (default: 60000) */
|
|
57
|
+
minAge?: number;
|
|
58
|
+
/** Priority boost per interval (default: 1) */
|
|
59
|
+
boost?: number;
|
|
60
|
+
/** Max priority cap (default: 100) */
|
|
61
|
+
maxPriority?: number;
|
|
62
|
+
/** Max jobs to scan per tick (default: 100) */
|
|
63
|
+
maxScan?: number;
|
|
64
|
+
}
|
|
65
|
+
/** Batch processor function */
|
|
66
|
+
export type BatchProcessor<T = unknown, R = unknown> = (jobs: Array<Job<T>>) => Promise<R[]>;
|
|
67
|
+
/** Batch processing configuration */
|
|
68
|
+
export interface BatchConfig<T = unknown, R = unknown> {
|
|
69
|
+
/** Batch size (default: 10) */
|
|
70
|
+
size: number;
|
|
71
|
+
/** Max wait in ms before flushing partial batch (default: 5000) */
|
|
72
|
+
timeout?: number;
|
|
73
|
+
/** Batch processor function */
|
|
74
|
+
processor: BatchProcessor<T, R>;
|
|
75
|
+
}
|
|
76
|
+
/** Job TTL configuration */
|
|
77
|
+
export interface JobTtlConfig {
|
|
78
|
+
/** Default TTL in ms (0 = no TTL) */
|
|
79
|
+
defaultTtl?: number;
|
|
80
|
+
/** Per-job-name TTL overrides */
|
|
81
|
+
perName?: Record<string, number>;
|
|
82
|
+
}
|
|
83
|
+
/** Bunqueue options */
|
|
84
|
+
export interface BunqueueOptions<T = unknown, R = unknown> {
|
|
85
|
+
processor?: Processor<T, R>;
|
|
86
|
+
routes?: Record<string, Processor<T, R>>;
|
|
87
|
+
batch?: BatchConfig<T, R>;
|
|
88
|
+
concurrency?: number;
|
|
89
|
+
connection?: ConnectionOptions;
|
|
90
|
+
embedded?: boolean;
|
|
91
|
+
dataPath?: string;
|
|
92
|
+
defaultJobOptions?: JobOptions;
|
|
93
|
+
autorun?: boolean;
|
|
94
|
+
heartbeatInterval?: number;
|
|
95
|
+
batchSize?: number;
|
|
96
|
+
pollTimeout?: number;
|
|
97
|
+
autoBatch?: QueueOptions['autoBatch'];
|
|
98
|
+
limiter?: WorkerOptions['limiter'];
|
|
99
|
+
removeOnComplete?: WorkerOptions['removeOnComplete'];
|
|
100
|
+
removeOnFail?: WorkerOptions['removeOnFail'];
|
|
101
|
+
retry?: RetryConfig;
|
|
102
|
+
circuitBreaker?: CircuitBreakerConfig;
|
|
103
|
+
ttl?: JobTtlConfig;
|
|
104
|
+
priorityAging?: PriorityAgingConfig;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/client/bunqueue/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,GAAG,EACH,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACd,MAAM,UAAU,CAAC;AAElB,mEAAmE;AACnE,MAAM,MAAM,kBAAkB,CAA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],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -1,87 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bunqueue - Simplified all-in-one Queue + Worker
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```typescript
|
|
6
|
-
* import { Bunqueue } from 'bunqueue/client';
|
|
7
|
-
*
|
|
8
|
-
* // Simple processor
|
|
9
|
-
* const q = new Bunqueue<{ email: string }>('emails', {
|
|
10
|
-
* processor: async (job) => {
|
|
11
|
-
* await job.updateProgress(50);
|
|
12
|
-
* return { sent: true };
|
|
13
|
-
* },
|
|
14
|
-
* concurrency: 5,
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* // Job routing
|
|
18
|
-
* const q2 = new Bunqueue('notifications', {
|
|
19
|
-
* routes: {
|
|
20
|
-
* 'send-email': async (job) => { ... },
|
|
21
|
-
* 'send-sms': async (job) => { ... },
|
|
22
|
-
* },
|
|
23
|
-
* });
|
|
24
|
-
*
|
|
25
|
-
* // Middleware
|
|
26
|
-
* q.use(async (job, next) => {
|
|
27
|
-
* const start = Date.now();
|
|
28
|
-
* const result = await next();
|
|
29
|
-
* console.log(`Done in ${Date.now() - start}ms`);
|
|
30
|
-
* return result;
|
|
31
|
-
* });
|
|
32
|
-
*
|
|
33
|
-
* // Cron
|
|
34
|
-
* q.cron('daily-report', '0 9 * * *', { type: 'summary' });
|
|
35
|
-
* ```
|
|
3
|
+
* Routes, middleware, cron, batch, retry, circuit breaker, TTL, aging, cancellation.
|
|
36
4
|
*/
|
|
37
5
|
import { Queue } from './queue/queue';
|
|
38
6
|
import { Worker } from './worker/worker';
|
|
39
|
-
import type { Job, JobOptions
|
|
7
|
+
import type { Job, JobOptions } from './types';
|
|
40
8
|
import type { SchedulerInfo } from './queue/scheduler';
|
|
41
|
-
|
|
42
|
-
export type BunqueueMiddleware
|
|
43
|
-
export interface BunqueueOptions<T = unknown, R = unknown> {
|
|
44
|
-
/** Job processor function (use this OR routes, not both) */
|
|
45
|
-
processor?: Processor<T, R>;
|
|
46
|
-
/** Named job processors — routes jobs by name to the right handler */
|
|
47
|
-
routes?: Record<string, Processor<T, R>>;
|
|
48
|
-
/** Worker concurrency (default: 1) */
|
|
49
|
-
concurrency?: number;
|
|
50
|
-
/** Connection options for TCP mode */
|
|
51
|
-
connection?: ConnectionOptions;
|
|
52
|
-
/** Use embedded mode (default: auto-detect) */
|
|
53
|
-
embedded?: boolean;
|
|
54
|
-
/** SQLite data path (embedded mode) */
|
|
55
|
-
dataPath?: string;
|
|
56
|
-
/** Default job options */
|
|
57
|
-
defaultJobOptions?: JobOptions;
|
|
58
|
-
/** Worker auto-start (default: true) */
|
|
59
|
-
autorun?: boolean;
|
|
60
|
-
/** Heartbeat interval in ms (default: 10000, 0=disabled) */
|
|
61
|
-
heartbeatInterval?: number;
|
|
62
|
-
/** Worker batch size (default: 10) */
|
|
63
|
-
batchSize?: number;
|
|
64
|
-
/** Long poll timeout in ms (default: 0) */
|
|
65
|
-
pollTimeout?: number;
|
|
66
|
-
/** Auto-batching options (TCP mode) */
|
|
67
|
-
autoBatch?: QueueOptions['autoBatch'];
|
|
68
|
-
/** Rate limiter options */
|
|
69
|
-
limiter?: WorkerOptions['limiter'];
|
|
70
|
-
/** Remove job on complete */
|
|
71
|
-
removeOnComplete?: WorkerOptions['removeOnComplete'];
|
|
72
|
-
/** Remove job on fail */
|
|
73
|
-
removeOnFail?: WorkerOptions['removeOnFail'];
|
|
74
|
-
}
|
|
9
|
+
import type { BunqueueOptions, BunqueueMiddleware, TriggerRule, CircuitState } from './bunqueue/types';
|
|
10
|
+
export type { BunqueueMiddleware, BunqueueOptions, RetryStrategy, RetryConfig, CircuitBreakerConfig, TriggerRule, PriorityAgingConfig, BatchProcessor, BatchConfig, JobTtlConfig, } from './bunqueue/types';
|
|
75
11
|
export declare class Bunqueue<T = unknown, R = unknown> {
|
|
76
12
|
readonly name: string;
|
|
77
13
|
readonly queue: Queue<T>;
|
|
78
14
|
readonly worker: Worker<T, R>;
|
|
79
15
|
private readonly middlewares;
|
|
80
16
|
private readonly baseProcessor;
|
|
17
|
+
private readonly cb;
|
|
18
|
+
private readonly retryConfig;
|
|
19
|
+
private readonly triggerMgr;
|
|
20
|
+
private readonly ager;
|
|
21
|
+
private readonly cancellation;
|
|
22
|
+
private readonly ttlChecker;
|
|
23
|
+
private readonly batchAcc;
|
|
81
24
|
constructor(name: string, opts: BunqueueOptions<T, R>);
|
|
82
|
-
|
|
25
|
+
private buildRouteProcessor;
|
|
26
|
+
private buildQueueOpts;
|
|
27
|
+
private buildWorkerOpts;
|
|
28
|
+
private processJob;
|
|
29
|
+
private runMiddlewareChain;
|
|
83
30
|
use(middleware: BunqueueMiddleware<T, R>): this;
|
|
84
|
-
private executeWithMiddleware;
|
|
85
31
|
add(name: string, data: T, opts?: JobOptions): Promise<Job<T>>;
|
|
86
32
|
addBulk(jobs: Array<{
|
|
87
33
|
name: string;
|
|
@@ -93,19 +39,23 @@ export declare class Bunqueue<T = unknown, R = unknown> {
|
|
|
93
39
|
getJobCountsAsync(): Promise<import("./queue/operations").JobCounts>;
|
|
94
40
|
count(): number;
|
|
95
41
|
countAsync(): Promise<number>;
|
|
96
|
-
|
|
97
|
-
cron(schedulerId: string, pattern: string, data?: T, opts?: {
|
|
42
|
+
cron(id: string, pattern: string, data?: T, opts?: {
|
|
98
43
|
timezone?: string;
|
|
99
44
|
jobOpts?: JobOptions;
|
|
100
45
|
}): Promise<SchedulerInfo | null>;
|
|
101
|
-
|
|
102
|
-
every(schedulerId: string, intervalMs: number, data?: T, opts?: {
|
|
46
|
+
every(id: string, intervalMs: number, data?: T, opts?: {
|
|
103
47
|
jobOpts?: JobOptions;
|
|
104
48
|
}): Promise<SchedulerInfo | null>;
|
|
105
|
-
|
|
106
|
-
removeCron(schedulerId: string): Promise<boolean>;
|
|
107
|
-
/** List all cron/repeating jobs */
|
|
49
|
+
removeCron(id: string): Promise<boolean>;
|
|
108
50
|
listCrons(): Promise<SchedulerInfo[]>;
|
|
51
|
+
cancel(jobId: string, gracePeriodMs?: number): void;
|
|
52
|
+
isCancelled(jobId: string): boolean;
|
|
53
|
+
getSignal(jobId: string): AbortSignal | null;
|
|
54
|
+
getCircuitState(): CircuitState;
|
|
55
|
+
resetCircuit(): void;
|
|
56
|
+
trigger(rule: TriggerRule<T>): this;
|
|
57
|
+
setDefaultTtl(ttlMs: number): void;
|
|
58
|
+
setNameTtl(name: string, ttlMs: number): void;
|
|
109
59
|
on(event: 'ready' | 'drained' | 'closed', listener: () => void): this;
|
|
110
60
|
on(event: 'active', listener: (job: Job<T>) => void): this;
|
|
111
61
|
on(event: 'completed', listener: (job: Job<T>, result: R) => void): this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bunqueue.d.ts","sourceRoot":"","sources":["../../src/client/bunqueue.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bunqueue.d.ts","sourceRoot":"","sources":["../../src/client/bunqueue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAuD,MAAM,SAAS,CAAC;AACpG,OAAO,KAAK,EAA2B,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,WAAW,EACX,YAAY,EACb,MAAM,kBAAkB,CAAC;AAU1B,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;I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EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;IAQzD,KAAK,IAAI,IAAI;IAIb,MAAM,IAAI,IAAI;IAKR,KAAK,CAAC,KAAK,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IASzC,SAAS,IAAI,OAAO;IAGpB,QAAQ,IAAI,OAAO;IAGnB,QAAQ,IAAI,OAAO;CAGpB"}
|
package/dist/client/bunqueue.js
CHANGED
|
@@ -1,85 +1,80 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bunqueue - Simplified all-in-one Queue + Worker
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```typescript
|
|
6
|
-
* import { Bunqueue } from 'bunqueue/client';
|
|
7
|
-
*
|
|
8
|
-
* // Simple processor
|
|
9
|
-
* const q = new Bunqueue<{ email: string }>('emails', {
|
|
10
|
-
* processor: async (job) => {
|
|
11
|
-
* await job.updateProgress(50);
|
|
12
|
-
* return { sent: true };
|
|
13
|
-
* },
|
|
14
|
-
* concurrency: 5,
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* // Job routing
|
|
18
|
-
* const q2 = new Bunqueue('notifications', {
|
|
19
|
-
* routes: {
|
|
20
|
-
* 'send-email': async (job) => { ... },
|
|
21
|
-
* 'send-sms': async (job) => { ... },
|
|
22
|
-
* },
|
|
23
|
-
* });
|
|
24
|
-
*
|
|
25
|
-
* // Middleware
|
|
26
|
-
* q.use(async (job, next) => {
|
|
27
|
-
* const start = Date.now();
|
|
28
|
-
* const result = await next();
|
|
29
|
-
* console.log(`Done in ${Date.now() - start}ms`);
|
|
30
|
-
* return result;
|
|
31
|
-
* });
|
|
32
|
-
*
|
|
33
|
-
* // Cron
|
|
34
|
-
* q.cron('daily-report', '0 9 * * *', { type: 'summary' });
|
|
35
|
-
* ```
|
|
3
|
+
* Routes, middleware, cron, batch, retry, circuit breaker, TTL, aging, cancellation.
|
|
36
4
|
*/
|
|
37
5
|
import { Queue } from './queue/queue';
|
|
38
6
|
import { Worker } from './worker/worker';
|
|
7
|
+
import { executeWithRetry } from './bunqueue/retry';
|
|
8
|
+
import { WorkerCircuitBreaker } from './bunqueue/circuitBreaker';
|
|
9
|
+
import { BatchAccumulator } from './bunqueue/batch';
|
|
10
|
+
import { TriggerManager } from './bunqueue/triggers';
|
|
11
|
+
import { PriorityAger } from './bunqueue/aging';
|
|
12
|
+
import { CancellationManager } from './bunqueue/cancellation';
|
|
13
|
+
import { TtlChecker } from './bunqueue/ttl';
|
|
39
14
|
export class Bunqueue {
|
|
40
15
|
name;
|
|
41
16
|
queue;
|
|
42
17
|
worker;
|
|
43
18
|
middlewares = [];
|
|
44
19
|
baseProcessor;
|
|
20
|
+
cb;
|
|
21
|
+
retryConfig;
|
|
22
|
+
triggerMgr;
|
|
23
|
+
ager;
|
|
24
|
+
cancellation = new CancellationManager();
|
|
25
|
+
ttlChecker;
|
|
26
|
+
batchAcc;
|
|
45
27
|
constructor(name, opts) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
throw new Error('Bunqueue: use "processor"
|
|
51
|
-
}
|
|
28
|
+
const modes = [opts.processor, opts.routes, opts.batch].filter(Boolean).length;
|
|
29
|
+
if (modes === 0)
|
|
30
|
+
throw new Error('Bunqueue requires "processor", "routes", or "batch"');
|
|
31
|
+
if (modes > 1)
|
|
32
|
+
throw new Error('Bunqueue: use only one of "processor", "routes", or "batch"');
|
|
52
33
|
this.name = name;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
throw new Error(`No route for job "${job.name}" in queue "${name}"`);
|
|
60
|
-
}
|
|
61
|
-
return handler(job);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
else if (opts.processor) {
|
|
65
|
-
this.baseProcessor = opts.processor;
|
|
34
|
+
this.retryConfig = opts.retry ?? null;
|
|
35
|
+
this.ttlChecker = opts.ttl ? new TtlChecker(opts.ttl) : null;
|
|
36
|
+
// Build base processor
|
|
37
|
+
if (opts.batch) {
|
|
38
|
+
this.batchAcc = new BatchAccumulator(opts.batch);
|
|
39
|
+
this.baseProcessor = this.batchAcc.buildProcessor();
|
|
66
40
|
}
|
|
67
41
|
else {
|
|
68
|
-
|
|
69
|
-
|
|
42
|
+
this.batchAcc = null;
|
|
43
|
+
this.baseProcessor = opts.routes ? this.buildRouteProcessor(opts.routes) : opts.processor; // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
70
44
|
}
|
|
71
|
-
// Wrapped processor that applies middleware chain
|
|
72
45
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
73
46
|
const self = this;
|
|
74
|
-
const wrappedProcessor = ((job) => self.
|
|
75
|
-
|
|
47
|
+
const wrappedProcessor = ((job) => self.processJob(job));
|
|
48
|
+
this.queue = new Queue(name, this.buildQueueOpts(opts));
|
|
49
|
+
this.worker = new Worker(name, wrappedProcessor, this.buildWorkerOpts(opts));
|
|
50
|
+
// Initialize subsystems
|
|
51
|
+
this.cb = opts.circuitBreaker
|
|
52
|
+
? new WorkerCircuitBreaker(opts.circuitBreaker, this.worker)
|
|
53
|
+
: null;
|
|
54
|
+
this.triggerMgr = new TriggerManager(this.queue, this.worker);
|
|
55
|
+
this.ager = opts.priorityAging ? new PriorityAger(opts.priorityAging, this.queue) : null;
|
|
56
|
+
this.ager?.start();
|
|
57
|
+
}
|
|
58
|
+
buildRouteProcessor(routes) {
|
|
59
|
+
const routeMap = routes;
|
|
60
|
+
return ((job) => {
|
|
61
|
+
const handler = routeMap[job.name];
|
|
62
|
+
if (!handler)
|
|
63
|
+
throw new Error(`No route for job "${job.name}" in queue "${this.name}"`);
|
|
64
|
+
return handler(job);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
buildQueueOpts(opts) {
|
|
68
|
+
return {
|
|
76
69
|
connection: opts.connection,
|
|
77
70
|
embedded: opts.embedded,
|
|
78
71
|
dataPath: opts.dataPath,
|
|
79
72
|
defaultJobOptions: opts.defaultJobOptions,
|
|
80
73
|
autoBatch: opts.autoBatch,
|
|
81
74
|
};
|
|
82
|
-
|
|
75
|
+
}
|
|
76
|
+
buildWorkerOpts(opts) {
|
|
77
|
+
return {
|
|
83
78
|
connection: opts.connection,
|
|
84
79
|
embedded: opts.embedded,
|
|
85
80
|
dataPath: opts.dataPath,
|
|
@@ -92,34 +87,55 @@ export class Bunqueue {
|
|
|
92
87
|
removeOnComplete: opts.removeOnComplete,
|
|
93
88
|
removeOnFail: opts.removeOnFail,
|
|
94
89
|
};
|
|
95
|
-
this.queue = new Queue(name, queueOpts);
|
|
96
|
-
this.worker = new Worker(name, wrappedProcessor, workerOpts);
|
|
97
|
-
}
|
|
98
|
-
// ============ Middleware ============
|
|
99
|
-
/** Add middleware to the processing pipeline */
|
|
100
|
-
use(middleware) {
|
|
101
|
-
this.middlewares.push(middleware);
|
|
102
|
-
return this;
|
|
103
90
|
}
|
|
104
|
-
|
|
91
|
+
// ============ Core Processing Pipeline ============
|
|
92
|
+
processJob(job) {
|
|
93
|
+
// Circuit breaker check
|
|
94
|
+
if (this.cb?.isOpen()) {
|
|
95
|
+
return Promise.reject(new Error('Circuit breaker is open'));
|
|
96
|
+
}
|
|
97
|
+
// TTL check
|
|
98
|
+
if (this.ttlChecker?.isExpired(job.name, job.timestamp)) {
|
|
99
|
+
return Promise.reject(new Error(`Job expired (age: ${Date.now() - job.timestamp}ms)`));
|
|
100
|
+
}
|
|
101
|
+
// Register cancellation
|
|
102
|
+
const ac = this.cancellation.register(job.id);
|
|
103
|
+
const runChain = () => this.runMiddlewareChain(job, ac);
|
|
104
|
+
const execute = this.retryConfig ? executeWithRetry(runChain, this.retryConfig) : runChain();
|
|
105
|
+
return execute.then((result) => {
|
|
106
|
+
this.cb?.onSuccess();
|
|
107
|
+
this.cancellation.unregister(job.id);
|
|
108
|
+
return result;
|
|
109
|
+
}, (err) => {
|
|
110
|
+
this.cb?.onFailure();
|
|
111
|
+
this.cancellation.unregister(job.id);
|
|
112
|
+
throw err;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
runMiddlewareChain(job, ac) {
|
|
105
116
|
const asJob = job;
|
|
106
117
|
if (this.middlewares.length === 0) {
|
|
107
118
|
const result = this.baseProcessor(job);
|
|
108
119
|
return result instanceof Promise ? result : Promise.resolve(result);
|
|
109
120
|
}
|
|
110
121
|
let index = 0;
|
|
111
|
-
const
|
|
112
|
-
const
|
|
122
|
+
const mws = this.middlewares;
|
|
123
|
+
const base = this.baseProcessor;
|
|
113
124
|
const next = () => {
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const result =
|
|
125
|
+
if (ac.signal.aborted)
|
|
126
|
+
return Promise.reject(new Error('Job cancelled'));
|
|
127
|
+
if (index < mws.length)
|
|
128
|
+
return mws[index++](asJob, next);
|
|
129
|
+
const result = base(job);
|
|
119
130
|
return result instanceof Promise ? result : Promise.resolve(result);
|
|
120
131
|
};
|
|
121
132
|
return next();
|
|
122
133
|
}
|
|
134
|
+
// ============ Middleware ============
|
|
135
|
+
use(middleware) {
|
|
136
|
+
this.middlewares.push(middleware);
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
123
139
|
// ============ Queue Operations ============
|
|
124
140
|
add(name, data, opts) {
|
|
125
141
|
return this.queue.add(name, data, opts);
|
|
@@ -143,34 +159,47 @@ export class Bunqueue {
|
|
|
143
159
|
return this.queue.countAsync();
|
|
144
160
|
}
|
|
145
161
|
// ============ Cron ============
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const repeatOpts = { pattern, timezone: opts?.timezone };
|
|
149
|
-
const jobTemplate = {
|
|
150
|
-
name: schedulerId,
|
|
151
|
-
data,
|
|
152
|
-
opts: opts?.jobOpts,
|
|
153
|
-
};
|
|
154
|
-
return this.queue.upsertJobScheduler(schedulerId, repeatOpts, jobTemplate);
|
|
155
|
-
}
|
|
156
|
-
/** Add a repeating job (every N ms) */
|
|
157
|
-
every(schedulerId, intervalMs, data, opts) {
|
|
158
|
-
const repeatOpts = { every: intervalMs };
|
|
159
|
-
const jobTemplate = {
|
|
160
|
-
name: schedulerId,
|
|
161
|
-
data,
|
|
162
|
-
opts: opts?.jobOpts,
|
|
163
|
-
};
|
|
164
|
-
return this.queue.upsertJobScheduler(schedulerId, repeatOpts, jobTemplate);
|
|
162
|
+
cron(id, pattern, data, opts) {
|
|
163
|
+
return this.queue.upsertJobScheduler(id, { pattern, timezone: opts?.timezone }, { name: id, data, opts: opts?.jobOpts });
|
|
165
164
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
every(id, intervalMs, data, opts) {
|
|
166
|
+
return this.queue.upsertJobScheduler(id, { every: intervalMs }, { name: id, data, opts: opts?.jobOpts });
|
|
167
|
+
}
|
|
168
|
+
removeCron(id) {
|
|
169
|
+
return this.queue.removeJobScheduler(id);
|
|
169
170
|
}
|
|
170
|
-
/** List all cron/repeating jobs */
|
|
171
171
|
listCrons() {
|
|
172
172
|
return this.queue.getJobSchedulers();
|
|
173
173
|
}
|
|
174
|
+
// ============ Cancellation (feature 3) ============
|
|
175
|
+
cancel(jobId, gracePeriodMs = 0) {
|
|
176
|
+
this.cancellation.cancel(jobId, gracePeriodMs);
|
|
177
|
+
}
|
|
178
|
+
isCancelled(jobId) {
|
|
179
|
+
return this.cancellation.isCancelled(jobId);
|
|
180
|
+
}
|
|
181
|
+
getSignal(jobId) {
|
|
182
|
+
return this.cancellation.getSignal(jobId);
|
|
183
|
+
}
|
|
184
|
+
// ============ Circuit Breaker (feature 5) ============
|
|
185
|
+
getCircuitState() {
|
|
186
|
+
return this.cb?.currentState ?? 'closed';
|
|
187
|
+
}
|
|
188
|
+
resetCircuit() {
|
|
189
|
+
this.cb?.reset();
|
|
190
|
+
}
|
|
191
|
+
// ============ Triggers (feature 6) ============
|
|
192
|
+
trigger(rule) {
|
|
193
|
+
this.triggerMgr.add(rule);
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
// ============ TTL (feature 7) ============
|
|
197
|
+
setDefaultTtl(ttlMs) {
|
|
198
|
+
this.ttlChecker?.setDefaultTtl(ttlMs);
|
|
199
|
+
}
|
|
200
|
+
setNameTtl(name, ttlMs) {
|
|
201
|
+
this.ttlChecker?.setNameTtl(name, ttlMs);
|
|
202
|
+
}
|
|
174
203
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
175
204
|
on(event, listener) {
|
|
176
205
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
@@ -199,6 +228,10 @@ export class Bunqueue {
|
|
|
199
228
|
this.worker.resume();
|
|
200
229
|
}
|
|
201
230
|
async close(force = false) {
|
|
231
|
+
this.ager?.destroy();
|
|
232
|
+
this.cb?.destroy();
|
|
233
|
+
this.batchAcc?.destroy();
|
|
234
|
+
this.cancellation.destroyAll();
|
|
202
235
|
await this.worker.close(force);
|
|
203
236
|
this.queue.close();
|
|
204
237
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bunqueue.js","sourceRoot":"","sources":["../../src/client/bunqueue.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bunqueue.js","sourceRoot":"","sources":["../../src/client/bunqueue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AASzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,mB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;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oCAAoC;IAEpC,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IACD,MAAM;QACJ,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACpB,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK;QACvB,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC;QACrB,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC;QACnB,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC;QACzB,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC;QAC/B,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;IACD,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IACD,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;CACF"}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
export { Queue } from './queue';
|
|
22
22
|
export { Worker } from './worker';
|
|
23
23
|
export { Bunqueue } from './bunqueue';
|
|
24
|
-
export type { BunqueueOptions, BunqueueMiddleware } from './bunqueue';
|
|
24
|
+
export type { BunqueueOptions, BunqueueMiddleware, RetryStrategy, RetryConfig, CircuitBreakerConfig, TriggerRule, PriorityAgingConfig, BatchProcessor, BatchConfig, JobTtlConfig, } from './bunqueue';
|
|
25
25
|
export { SandboxedWorker } from './sandboxedWorker';
|
|
26
26
|
export { QueueEvents } from './events';
|
|
27
27
|
export { QueueGroup } from './queueGroup';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAClF,YAAY,EACV,GAAG,EACH,UAAU,EACV,OAAO,EACP,UAAU,EACV,YAAY,EACZ,aAAa,EACb,SAAS,EACT,WAAW,EACX,WAAW,EACX,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,oBAAoB,GACrB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACpG,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAChF,YAAY,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAatC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunqueue",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.91",
|
|
4
4
|
"description": "High-performance job queue for Bun & AI agents. SQLite persistence, cron scheduling, priorities, retries, DLQ, webhooks, native MCP server. Zero external dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|