@nathapp/nestjs-event-bus 1.4.0 → 1.6.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.
- package/README.md +123 -0
- package/dist/constant/index.d.ts +3 -0
- package/dist/constant/index.js +7 -1
- package/dist/constant/index.js.map +1 -1
- package/dist/interface/event-bus-options.interface.d.ts +6 -0
- package/dist/interface/idempotency-store.interface.d.ts +3 -2
- package/dist/module/event-bus.module.js +6 -2
- package/dist/module/event-bus.module.js.map +1 -1
- package/dist/provider/event-emitter.provider.d.ts +18 -4
- package/dist/provider/event-emitter.provider.js +179 -64
- package/dist/provider/event-emitter.provider.js.map +1 -1
- package/dist/provider/idempotency-store.d.ts +6 -2
- package/dist/provider/idempotency-store.js +41 -9
- package/dist/provider/idempotency-store.js.map +1 -1
- package/dist/provider/job-store.d.ts +6 -2
- package/dist/provider/job-store.js +32 -8
- package/dist/provider/job-store.js.map +1 -1
- package/dist/provider/redis-idempotency-store.d.ts +2 -2
- package/dist/provider/redis-idempotency-store.js +44 -6
- package/dist/provider/redis-idempotency-store.js.map +1 -1
- package/dist/service/event-bus-bridge.service.d.ts +1 -0
- package/dist/service/event-bus-bridge.service.js +23 -3
- package/dist/service/event-bus-bridge.service.js.map +1 -1
- package/dist/util/with-idempotency.d.ts +1 -0
- package/dist/util/with-idempotency.js +18 -4
- package/dist/util/with-idempotency.js.map +1 -1
- package/package.json +9 -9
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# @nathapp/nestjs-event-bus
|
|
2
|
+
|
|
3
|
+
In-process job queue and event bridge for NestJS. `EventBusModule.register()`
|
|
4
|
+
(or `registerAsync()`) provides an `EventEmitterProvider` under `QUEUE_PROVIDER`,
|
|
5
|
+
an idempotency store under `IDEMPOTENCY_STORE` and a dead-letter store under
|
|
6
|
+
`DEAD_LETTER_STORE`. With `enableBridge: true` it also forwards matching local
|
|
7
|
+
`EventEmitter2` events to an external queue service.
|
|
8
|
+
|
|
9
|
+
The provider and the default stores are in-memory: jobs, claims and results are
|
|
10
|
+
lost on restart and are not shared between instances.
|
|
11
|
+
|
|
12
|
+
## Jobs consumed only by event listeners
|
|
13
|
+
|
|
14
|
+
Every dispatched job is emitted on the shared `EventEmitter2` as
|
|
15
|
+
`<queue>.<jobName>`. When the queue has no processor for the job name, none for
|
|
16
|
+
`'*'`, and no `processBatch` handler, the job is marked COMPLETED (and
|
|
17
|
+
`QueueEvent.COMPLETED` fires) right after that emit. Such jobs therefore count
|
|
18
|
+
towards `maxJobs` and are evicted like any finished job, and a graceful
|
|
19
|
+
`close()` does not emit them a second time. A job added to a paused queue stays
|
|
20
|
+
WAITING until `resume()`.
|
|
21
|
+
|
|
22
|
+
## Job store bounds
|
|
23
|
+
|
|
24
|
+
`maxJobs` (default 10 000) caps the stored jobs. When it is exceeded, the
|
|
25
|
+
oldest finished (COMPLETED or FAILED) jobs are evicted, in finish order.
|
|
26
|
+
WAITING, ACTIVE and DELAYED jobs are never evicted, so the store can exceed
|
|
27
|
+
`maxJobs` while that many jobs are pending. Finished jobs also expire after
|
|
28
|
+
`jobTTL` (default 24 h).
|
|
29
|
+
|
|
30
|
+
## Retries and backoff
|
|
31
|
+
|
|
32
|
+
A failed attempt with attempts left is rescheduled as a delayed job: the job
|
|
33
|
+
becomes DELAYED, its concurrency slot is released at once, and the next attempt
|
|
34
|
+
runs after the backoff. Other jobs on the queue run in the meantime.
|
|
35
|
+
|
|
36
|
+
| `backoff` | Delay before the next attempt |
|
|
37
|
+
|---|---|
|
|
38
|
+
| a number | that many ms |
|
|
39
|
+
| `{ type: 'fixed', delay }` | `delay` |
|
|
40
|
+
| `{ type: 'exponential', delay }` | `delay * 2^(attemptsMade - 1)` |
|
|
41
|
+
|
|
42
|
+
Every delay is capped at `maxBackoffMs` (default 600 000 ms, 10 minutes;
|
|
43
|
+
`DEFAULT_MAX_BACKOFF_MS`). A value that is not a positive safe integer throws a
|
|
44
|
+
`RangeError` at construction.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
EventBusModule.register({ maxBackoffMs: 60_000 });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- `QueueEvent.ACTIVE` fires at the start of every attempt; the `<queue>.<jobName>`
|
|
51
|
+
event and `QueueEvent.WAITING` fire only on the first dispatch.
|
|
52
|
+
- The final failure writes the dead-letter record (when `deadLetter.enabled`)
|
|
53
|
+
and marks the job FAILED.
|
|
54
|
+
- A graceful `close({ timeout })` waits for pending retries like any delayed
|
|
55
|
+
job, up to its timeout, then clears their timers. A forced close clears them
|
|
56
|
+
at once. `removeJob` cancels a pending retry.
|
|
57
|
+
|
|
58
|
+
## Handler idempotency
|
|
59
|
+
|
|
60
|
+
`withIdempotency(handler, { store })` wraps a job handler so a redelivered job
|
|
61
|
+
id runs once: the first run claims the key, a duplicate gets the stored result
|
|
62
|
+
(or is rejected or skipped while the first run is in flight, per
|
|
63
|
+
`inFlightPolicy`).
|
|
64
|
+
|
|
65
|
+
- `storeResult: false` stores a marker instead of the handler's return value; a
|
|
66
|
+
duplicate then resolves to `undefined`. Default `true`.
|
|
67
|
+
- `ttlMs` (default 24 h) is how long a completed key is remembered.
|
|
68
|
+
|
|
69
|
+
`InMemoryIdempotencyStore` (the default `IDEMPOTENCY_STORE`) holds at most
|
|
70
|
+
`maxEntries` keys (default 10 000; `DEFAULT_IDEMPOTENCY_MAX_ENTRIES`). At the
|
|
71
|
+
cap it evicts the oldest completed key first, and the oldest in-flight claim
|
|
72
|
+
only when it holds no completed keys (which can let that key run twice).
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
EventBusModule.register({ idempotency: { maxEntries: 50_000, claimTtlMs: 60_000 } });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Claim ownership
|
|
79
|
+
|
|
80
|
+
`begin()` returns an owner token with a fresh claim, and `withIdempotency`
|
|
81
|
+
passes it to `complete()` and `release()`. With a token, `release` deletes only
|
|
82
|
+
the claim that token holds, and `complete` writes only when the key is absent or
|
|
83
|
+
holds that same claim. It never replaces a completed result or another
|
|
84
|
+
worker's claim. A worker that outlived its claim TTL therefore cannot free or
|
|
85
|
+
overwrite the claim of the worker that took over. `InMemoryIdempotencyStore`
|
|
86
|
+
and `RedisIdempotencyStore` both implement this; a custom `IIdempotencyStore`
|
|
87
|
+
may ignore the optional token and keeps its current behaviour.
|
|
88
|
+
|
|
89
|
+
## Bridge: secret-carrying events
|
|
90
|
+
|
|
91
|
+
Some platform events carry secrets in their payload because that is how the
|
|
92
|
+
consumer delivers them:
|
|
93
|
+
|
|
94
|
+
| Event | Secret in the payload |
|
|
95
|
+
|---|---|
|
|
96
|
+
| `iam.password.reset_requested` | the plaintext reset token |
|
|
97
|
+
| `oauth.device_code.issued` | the device `userCode` |
|
|
98
|
+
|
|
99
|
+
Treat these payloads as secret. A wildcard bridge pattern (`'*'`, `'iam.*'`)
|
|
100
|
+
never forwards them (`DEFAULT_SENSITIVE_EVENTS`). Registering one by its exact
|
|
101
|
+
name still forwards it and logs a warning. Add your own names with
|
|
102
|
+
`sensitiveEvents` (exact names, matched literally; the defaults always apply).
|
|
103
|
+
|
|
104
|
+
`redactPayload(eventName, payload)` runs synchronously before every bridged
|
|
105
|
+
publish, and its return value is what reaches the queue. When it throws, or
|
|
106
|
+
returns a Promise, the event is not published and an error is logged. Return a
|
|
107
|
+
new object; do not mutate the payload, because other listeners share it.
|
|
108
|
+
|
|
109
|
+
Bridge `jobOptions` accept `removeOnComplete` and `removeOnFail`, so bridged
|
|
110
|
+
jobs need not stay in the external queue after processing. Numeric values are
|
|
111
|
+
honoured by queue providers that support them, such as BullMQ.
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
EventBusModule.register({
|
|
115
|
+
enableBridge: true,
|
|
116
|
+
queueService,
|
|
117
|
+
sensitiveEvents: ['billing.card_tokenized'],
|
|
118
|
+
redactPayload: (eventName, payload) => stripPersonalData(payload),
|
|
119
|
+
events: [{ pattern: 'order.*', queue: 'orders', jobOptions: { removeOnComplete: true } }],
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`stripPersonalData` is your own function.
|
package/dist/constant/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export declare const DEFAULT_DLQ_MAX_SIZE = 1000;
|
|
2
2
|
export declare const DEFAULT_IDEMPOTENCY_CLAIM_TTL_MS = 60000;
|
|
3
3
|
export declare const DEFAULT_IDEMPOTENCY_SWEEP_MS = 60000;
|
|
4
|
+
export declare const DEFAULT_IDEMPOTENCY_MAX_ENTRIES = 10000;
|
|
5
|
+
export declare const DEFAULT_MAX_BACKOFF_MS = 600000;
|
|
6
|
+
export declare const DEFAULT_SENSITIVE_EVENTS: string[];
|
|
4
7
|
export * from './tokens';
|
package/dist/constant/index.js
CHANGED
|
@@ -14,9 +14,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.DEFAULT_IDEMPOTENCY_SWEEP_MS = exports.DEFAULT_IDEMPOTENCY_CLAIM_TTL_MS = exports.DEFAULT_DLQ_MAX_SIZE = void 0;
|
|
17
|
+
exports.DEFAULT_SENSITIVE_EVENTS = exports.DEFAULT_MAX_BACKOFF_MS = exports.DEFAULT_IDEMPOTENCY_MAX_ENTRIES = exports.DEFAULT_IDEMPOTENCY_SWEEP_MS = exports.DEFAULT_IDEMPOTENCY_CLAIM_TTL_MS = exports.DEFAULT_DLQ_MAX_SIZE = void 0;
|
|
18
18
|
exports.DEFAULT_DLQ_MAX_SIZE = 1000;
|
|
19
19
|
exports.DEFAULT_IDEMPOTENCY_CLAIM_TTL_MS = 60000;
|
|
20
20
|
exports.DEFAULT_IDEMPOTENCY_SWEEP_MS = 60000;
|
|
21
|
+
exports.DEFAULT_IDEMPOTENCY_MAX_ENTRIES = 10000;
|
|
22
|
+
exports.DEFAULT_MAX_BACKOFF_MS = 600000;
|
|
23
|
+
exports.DEFAULT_SENSITIVE_EVENTS = [
|
|
24
|
+
'iam.password.reset_requested',
|
|
25
|
+
'oauth.device_code.issued',
|
|
26
|
+
];
|
|
21
27
|
__exportStar(require("./tokens"), exports);
|
|
22
28
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/constant/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAa,QAAA,oBAAoB,GAAG,IAAI,CAAC;AAC5B,QAAA,gCAAgC,GAAG,KAAM,CAAC;AAC1C,QAAA,4BAA4B,GAAG,KAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/constant/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAa,QAAA,oBAAoB,GAAG,IAAI,CAAC;AAC5B,QAAA,gCAAgC,GAAG,KAAM,CAAC;AAC1C,QAAA,4BAA4B,GAAG,KAAM,CAAC;AACtC,QAAA,+BAA+B,GAAG,KAAM,CAAC;AAEzC,QAAA,sBAAsB,GAAG,MAAO,CAAC;AACjC,QAAA,wBAAwB,GAAG;IACtC,8BAA8B;IAC9B,0BAA0B;CAC3B,CAAC;AAEF,2CAAyB"}
|
|
@@ -12,6 +12,8 @@ export interface IEventBridgeConfig {
|
|
|
12
12
|
priority?: number;
|
|
13
13
|
delay?: number;
|
|
14
14
|
attempts?: number;
|
|
15
|
+
removeOnComplete?: boolean | number;
|
|
16
|
+
removeOnFail?: boolean | number;
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
19
|
export interface IEventBusOptions {
|
|
@@ -19,11 +21,14 @@ export interface IEventBusOptions {
|
|
|
19
21
|
jobTTL?: number;
|
|
20
22
|
cleanupIntervalMs?: number;
|
|
21
23
|
concurrency?: number;
|
|
24
|
+
maxBackoffMs?: number;
|
|
22
25
|
enableBridge?: boolean;
|
|
23
26
|
events?: IEventBridgeConfig[];
|
|
24
27
|
defaultQueue?: string;
|
|
25
28
|
queueService?: IEventBusQueueService;
|
|
26
29
|
durableEvents?: string[];
|
|
30
|
+
sensitiveEvents?: string[];
|
|
31
|
+
redactPayload?: (eventName: string, payload: unknown) => unknown;
|
|
27
32
|
services?: {
|
|
28
33
|
bridge?: import('@nathapp/nestjs-common').ProviderClassOrAsyncOptions<IEventBusBridge>;
|
|
29
34
|
};
|
|
@@ -31,6 +36,7 @@ export interface IEventBusOptions {
|
|
|
31
36
|
store?: import('@nathapp/nestjs-common').ProviderClassOrAsyncOptions<IIdempotencyStore>;
|
|
32
37
|
claimTtlMs?: number;
|
|
33
38
|
sweepIntervalMs?: number;
|
|
39
|
+
maxEntries?: number;
|
|
34
40
|
};
|
|
35
41
|
deadLetter?: {
|
|
36
42
|
enabled?: boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type IdempotencyLookup<R> = {
|
|
2
2
|
state: 'new';
|
|
3
|
+
token?: string;
|
|
3
4
|
} | {
|
|
4
5
|
state: 'in_flight';
|
|
5
6
|
} | {
|
|
@@ -8,7 +9,7 @@ export type IdempotencyLookup<R> = {
|
|
|
8
9
|
};
|
|
9
10
|
export interface IIdempotencyStore {
|
|
10
11
|
begin<R>(key: string, ttlMs: number): Promise<IdempotencyLookup<R>>;
|
|
11
|
-
complete<R>(key: string, result: R, ttlMs: number): Promise<void>;
|
|
12
|
-
release(key: string): Promise<void>;
|
|
12
|
+
complete<R>(key: string, result: R, ttlMs: number, token?: string): Promise<void>;
|
|
13
|
+
release(key: string, token?: string): Promise<void>;
|
|
13
14
|
sweep?(): number;
|
|
14
15
|
}
|
|
@@ -60,10 +60,11 @@ let EventBusModule = EventBusModule_1 = class EventBusModule {
|
|
|
60
60
|
? {
|
|
61
61
|
provide: constant_1.IDEMPOTENCY_STORE,
|
|
62
62
|
useFactory: () => {
|
|
63
|
-
var _a, _b, _c;
|
|
63
|
+
var _a, _b, _c, _d, _e;
|
|
64
64
|
return new provider_1.InMemoryIdempotencyStore({
|
|
65
65
|
claimTtlMs: (_b = (_a = options.idempotency) === null || _a === void 0 ? void 0 : _a.claimTtlMs) !== null && _b !== void 0 ? _b : constant_1.DEFAULT_IDEMPOTENCY_CLAIM_TTL_MS,
|
|
66
66
|
sweepIntervalMs: (_c = options.idempotency) === null || _c === void 0 ? void 0 : _c.sweepIntervalMs,
|
|
67
|
+
maxEntries: (_e = (_d = options.idempotency) === null || _d === void 0 ? void 0 : _d.maxEntries) !== null && _e !== void 0 ? _e : constant_1.DEFAULT_IDEMPOTENCY_MAX_ENTRIES,
|
|
67
68
|
});
|
|
68
69
|
},
|
|
69
70
|
}
|
|
@@ -87,6 +88,7 @@ let EventBusModule = EventBusModule_1 = class EventBusModule {
|
|
|
87
88
|
maxJobs: options.maxJobs,
|
|
88
89
|
jobTTL: options.jobTTL,
|
|
89
90
|
cleanupIntervalMs: options.cleanupIntervalMs,
|
|
91
|
+
maxBackoffMs: options.maxBackoffMs,
|
|
90
92
|
deadLetterStore: deadLetterEnabled ? deadLetterStore : undefined,
|
|
91
93
|
});
|
|
92
94
|
return new EventEmitterProviderWrapper(provider);
|
|
@@ -138,11 +140,12 @@ let EventBusModule = EventBusModule_1 = class EventBusModule {
|
|
|
138
140
|
{
|
|
139
141
|
provide: constant_1.IDEMPOTENCY_STORE,
|
|
140
142
|
useFactory: (opts, moduleRef) => {
|
|
141
|
-
var _a, _b, _c, _d;
|
|
143
|
+
var _a, _b, _c, _d, _e, _f;
|
|
142
144
|
if (((_a = opts.idempotency) === null || _a === void 0 ? void 0 : _a.store) === undefined) {
|
|
143
145
|
return new provider_1.InMemoryIdempotencyStore({
|
|
144
146
|
claimTtlMs: (_c = (_b = opts.idempotency) === null || _b === void 0 ? void 0 : _b.claimTtlMs) !== null && _c !== void 0 ? _c : constant_1.DEFAULT_IDEMPOTENCY_CLAIM_TTL_MS,
|
|
145
147
|
sweepIntervalMs: (_d = opts.idempotency) === null || _d === void 0 ? void 0 : _d.sweepIntervalMs,
|
|
148
|
+
maxEntries: (_f = (_e = opts.idempotency) === null || _e === void 0 ? void 0 : _e.maxEntries) !== null && _f !== void 0 ? _f : constant_1.DEFAULT_IDEMPOTENCY_MAX_ENTRIES,
|
|
146
149
|
});
|
|
147
150
|
}
|
|
148
151
|
return resolveStoreInstance(opts.idempotency.store, provider_1.InMemoryIdempotencyStore, moduleRef);
|
|
@@ -171,6 +174,7 @@ let EventBusModule = EventBusModule_1 = class EventBusModule {
|
|
|
171
174
|
maxJobs: opts.maxJobs,
|
|
172
175
|
jobTTL: opts.jobTTL,
|
|
173
176
|
cleanupIntervalMs: opts.cleanupIntervalMs,
|
|
177
|
+
maxBackoffMs: opts.maxBackoffMs,
|
|
174
178
|
deadLetterStore: ((_a = opts.deadLetter) === null || _a === void 0 ? void 0 : _a.enabled) === true ? deadLetterStore : undefined,
|
|
175
179
|
});
|
|
176
180
|
return new EventEmitterProviderWrapper(provider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.module.js","sourceRoot":"","sources":["../../lib/module/event-bus.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAkF;AAClF,uCAA0D;AAC1D,yDAA0E;AAC1E,0DAA+E;AAC/E,
|
|
1
|
+
{"version":3,"file":"event-bus.module.js","sourceRoot":"","sources":["../../lib/module/event-bus.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAkF;AAClF,uCAA0D;AAC1D,yDAA0E;AAC1E,0DAA+E;AAC/E,0CAUqB;AAMrB,0CAAsG;AACtG,wCAA4E;AAS5E,MAAM,2BAA2B;IAC/B,YAA4B,QAA8B;QAA9B,aAAQ,GAAR,QAAQ,CAAsB;IAAG,CAAC;IAE9D,eAAe;QACb,KAAK,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC;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;gBACvB,UAAU,EAAE,CAAC,OAAoC,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ;gBACtE,MAAM,EAAE,CAAC,2BAA2B,CAAC;aACtC;YAED;gBACE,OAAO,EAAE,wBAAa;gBACtB,UAAU,EAAE,CAAC,IAAsB,EAAE,EAAE,WAAC,OAAA,MAAA,IAAI,CAAC,YAAY,mCAAI,IAAI,CAAA,EAAA;gBACjE,MAAM,EAAE,CAAC,4BAAiB,CAAC;aAC5B;YACD,IAAA,qDAAqC,EACnC,2BAAgB,EAChB,MAAA,QAAQ,CAAC,MAAM,mCAAI,+BAAqB,CACzC;YACD,iCAAuB;SACxB,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,gBAAc;YACtB,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE;gBACP,kCAAkB,CAAC,OAAO,EAAE;gBAC5B,sBAAe;gBACf,GAAG,CAAC,MAAA,OAAO,CAAC,OAAO,mCAAI,EAAE,CAAC;aAC3B;YACD,SAAS;YACT,OAAO,EAAE;gBACP,yBAAc;gBACd,4BAAiB;gBACjB,4BAAiB;gBACjB,4BAAiB;gBACjB,2BAAgB;aACjB;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA1LY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,cAAc,CA0L1B"}
|
|
@@ -4,7 +4,7 @@ import { IJob, JobOptions, ProcessorOptions } from '../interface/job.interface';
|
|
|
4
4
|
import { JobStatus } from '../enum/job-status.enum';
|
|
5
5
|
import { QueueEvent } from '../enum/queue-event.enum';
|
|
6
6
|
import { HealthCheckResult } from '../interface/health.interface';
|
|
7
|
-
import { IJobStoreAdapter } from './job-store';
|
|
7
|
+
import { IJobStoreAdapter, StoredJob } from './job-store';
|
|
8
8
|
import { DeadLetterRecord, IDeadLetterStore } from '../interface/dead-letter-store.interface';
|
|
9
9
|
export interface EventEmitterProviderOptions {
|
|
10
10
|
concurrency?: number;
|
|
@@ -13,6 +13,7 @@ export interface EventEmitterProviderOptions {
|
|
|
13
13
|
cleanupIntervalMs?: number;
|
|
14
14
|
jobStore?: IJobStoreAdapter;
|
|
15
15
|
deadLetterStore?: IDeadLetterStore;
|
|
16
|
+
maxBackoffMs?: number;
|
|
16
17
|
}
|
|
17
18
|
export declare class EventEmitterProvider implements IQueueProvider {
|
|
18
19
|
readonly type = "event-emitter";
|
|
@@ -23,12 +24,14 @@ export declare class EventEmitterProvider implements IQueueProvider {
|
|
|
23
24
|
private batchStates;
|
|
24
25
|
private readonly batchHandlers;
|
|
25
26
|
private readonly delayedJobs;
|
|
27
|
+
private readonly attemptGenerations;
|
|
26
28
|
private readonly deadLetterStore?;
|
|
27
29
|
private readonly defaultConcurrency;
|
|
30
|
+
private readonly maxBackoffMs;
|
|
28
31
|
private closing;
|
|
29
32
|
private closed;
|
|
30
33
|
constructor(eventEmitter: EventEmitter2, options?: EventEmitterProviderOptions);
|
|
31
|
-
add<T>(queueName: string, jobName: string, data: T, opts?: JobOptions): Promise<
|
|
34
|
+
add<T>(queueName: string, jobName: string, data: T, opts?: JobOptions): Promise<StoredJob<T>>;
|
|
32
35
|
addBulk<T>(queueName: string, jobs: Array<{
|
|
33
36
|
name: string;
|
|
34
37
|
data: T;
|
|
@@ -41,7 +44,7 @@ export declare class EventEmitterProvider implements IQueueProvider {
|
|
|
41
44
|
data: T;
|
|
42
45
|
opts?: JobOptions;
|
|
43
46
|
}>, batchId?: string): Promise<IJob<T>[]>;
|
|
44
|
-
getJob<T>(queueName: string, jobId: string): Promise<
|
|
47
|
+
getJob<T>(queueName: string, jobId: string): Promise<StoredJob<T> | null>;
|
|
45
48
|
getJobs(queueName: string, status: JobStatus[], start?: number, end?: number): Promise<IJob[]>;
|
|
46
49
|
removeJob(queueName: string, jobId: string): Promise<void>;
|
|
47
50
|
pause(queueName: string): Promise<void>;
|
|
@@ -62,18 +65,29 @@ export declare class EventEmitterProvider implements IQueueProvider {
|
|
|
62
65
|
private getOrCreateQueue;
|
|
63
66
|
private emitJob;
|
|
64
67
|
private processJob;
|
|
68
|
+
private runSingleAttempt;
|
|
69
|
+
private settleFailedAttempt;
|
|
70
|
+
private scheduleRetry;
|
|
71
|
+
private runRetry;
|
|
65
72
|
private drainProcessor;
|
|
66
73
|
private isTrackedByProcessor;
|
|
67
74
|
private hasExistingJob;
|
|
75
|
+
private attemptKey;
|
|
76
|
+
private admitGeneration;
|
|
77
|
+
private adoptGeneration;
|
|
78
|
+
private ownsAttempt;
|
|
79
|
+
private releaseGeneration;
|
|
80
|
+
private readStoredJob;
|
|
68
81
|
private isWaitingJob;
|
|
69
82
|
private isDelayedJob;
|
|
70
83
|
private isStoredJobInStatus;
|
|
71
84
|
private assertValidConcurrency;
|
|
85
|
+
private assertValidMaxBackoffMs;
|
|
72
86
|
private assertOpen;
|
|
73
87
|
private flushBatch;
|
|
74
88
|
private emit;
|
|
75
89
|
private matchesFilter;
|
|
76
|
-
private
|
|
90
|
+
private calculateRetryDelay;
|
|
77
91
|
private executeWithTimeout;
|
|
78
92
|
private waitForQueueJobs;
|
|
79
93
|
}
|