@fluojs/event-bus 1.0.0-beta.6 → 1.0.0-beta.7
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.ko.md +3 -3
- package/README.md +3 -3
- package/dist/service.d.ts +9 -2
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +73 -19
- package/dist/status.d.ts +2 -0
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +4 -2
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
package/README.ko.md
CHANGED
|
@@ -75,7 +75,7 @@ export class UserService {
|
|
|
75
75
|
export class AppModule {}
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
`publish(event, options?)`는 `signal`, `timeoutMs`, `waitForHandlers`를 지원합니다. `waitForHandlers`의 기본값은 `true`이며, 기다리는 로컬 핸들러와 기다리는 트랜스포트 publish는 동일한 timeout 및 cancellation bound를 공유합니다. `waitForHandlers`를 `false`로 설정하면 publish가 즉시 반환되고 timeout bound를 적용하지 않습니다. Shutdown 중에는 이벤트 버스가 진행 중인 awaited publish 작업을 drain한 뒤 트랜스포트를 닫고, lifecycle이 stopping에 진입한 뒤의 새 publish
|
|
78
|
+
`publish(event, options?)`는 `signal`, `timeoutMs`, `waitForHandlers`를 지원합니다. `waitForHandlers`의 기본값은 `true`이며, 기다리는 로컬 핸들러와 기다리는 트랜스포트 publish는 동일한 timeout 및 cancellation bound를 공유합니다. `waitForHandlers`를 `false`로 설정하면 publish가 즉시 반환되고 timeout bound를 적용하지 않습니다. Shutdown 중에는 이벤트 버스가 진행 중인 awaited publish 및 inbound transport handler 작업을 drain한 뒤 트랜스포트를 닫고, lifecycle이 stopping에 진입한 뒤의 새 publish 호출과 shutdown 시작 뒤 도착한 inbound transport callback은 무시합니다. Shutdown drain은 기본값이 5000ms인 `EventBusModule.forRoot({ shutdown: { drainTimeoutMs } })`로 제한됩니다. 활성 dispatch 작업이 이 bound 이후에도 멈춰 있으면 bus는 degraded status diagnostic을 기록하고 경고를 남긴 뒤, 애플리케이션 close를 무기한 hang시키지 않고 transport cleanup을 계속합니다.
|
|
79
79
|
|
|
80
80
|
## 일반적인 패턴
|
|
81
81
|
|
|
@@ -104,7 +104,7 @@ class UserRegisteredEvent {
|
|
|
104
104
|
}
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
핸들러는 imported module의 singleton provider와 controller에서 발견됩니다. 각 핸들러는 격리된 clone payload를 받으며, class inheritance는 `instanceof` 매칭으로 지원됩니다.
|
|
107
|
+
핸들러는 imported module의 singleton provider와 controller에서 발견됩니다. 각 핸들러는 격리된 clone payload를 받으며, class inheritance는 `instanceof` 매칭으로 지원됩니다. 외부 트랜스포트를 구성하면 subclass event publish는 publisher process에 해당 타입의 local handler가 없더라도 subclass channel과 prototype chain의 모든 inherited event channel로 fan-out됩니다. Subclass가 직접 `static eventKey`를 선언한 경우에만 그 값을 사용하며, 그렇지 않으면 subclass channel은 class name을 유지하고 base class는 자신의 stable key를 유지합니다.
|
|
108
108
|
|
|
109
109
|
## 공개 API 개요
|
|
110
110
|
|
|
@@ -120,7 +120,7 @@ class UserRegisteredEvent {
|
|
|
120
120
|
- `EventBus`, `EventPublishOptions`, `EventBusModuleOptions`, `EventType`: 발행, 기본값, 트랜스포트, 안정적인 이벤트 키를 위한 타입 전용 계약입니다.
|
|
121
121
|
- `EventBusLifecycleState`, `EventBusStatusAdapterInput`, `EventBusPlatformStatusSnapshot`: status snapshot 계약입니다.
|
|
122
122
|
|
|
123
|
-
Transport bootstrap은 unique event channel마다 한 번만 subscribe합니다. `eventKey`가 있으면 transport channel 이름을 제어합니다. 잘못된 JSON transport message는 무시됩니다.
|
|
123
|
+
Transport bootstrap은 unique event channel마다 한 번만 subscribe합니다. `eventKey`가 있으면 transport channel 이름을 제어합니다. 잘못된 JSON transport message는 무시되며, shutdown 시작 뒤 도착한 inbound transport message는 local handler dispatch 전에 무시됩니다.
|
|
124
124
|
|
|
125
125
|
## 런타임별 및 통합 서브패스
|
|
126
126
|
|
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ export class UserService {
|
|
|
75
75
|
export class AppModule {}
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
`publish(event, options?)` supports `signal`, `timeoutMs`, and `waitForHandlers`. `waitForHandlers` defaults to `true`; awaited local handlers and awaited transport publishes share the same timeout and cancellation bounds. When `waitForHandlers` is set to `false`, publishing returns immediately and skips timeout bounds. During shutdown, the event bus drains in-flight awaited publish work before closing the transport
|
|
78
|
+
`publish(event, options?)` supports `signal`, `timeoutMs`, and `waitForHandlers`. `waitForHandlers` defaults to `true`; awaited local handlers and awaited transport publishes share the same timeout and cancellation bounds. When `waitForHandlers` is set to `false`, publishing returns immediately and skips timeout bounds. During shutdown, the event bus drains in-flight awaited publish and inbound transport handler work before closing the transport, ignores new publish calls after the lifecycle has started stopping, and ignores inbound transport callbacks that arrive after shutdown begins. Shutdown drain is bounded by `EventBusModule.forRoot({ shutdown: { drainTimeoutMs } })`, which defaults to 5000ms; if active dispatch work is still stuck after the bound, the bus records a degraded status diagnostic, logs a warning, and continues transport cleanup instead of hanging application close indefinitely.
|
|
79
79
|
|
|
80
80
|
## Common Patterns
|
|
81
81
|
|
|
@@ -104,7 +104,7 @@ class UserRegisteredEvent {
|
|
|
104
104
|
}
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
Handlers are discovered from singleton providers and controllers across imported modules. Each handler receives an isolated cloned payload, and class inheritance is supported through `instanceof` matching.
|
|
107
|
+
Handlers are discovered from singleton providers and controllers across imported modules. Each handler receives an isolated cloned payload, and class inheritance is supported through `instanceof` matching. With an external transport configured, publishing a subclass event fans out to the subclass channel and every inherited event channel in its prototype chain, even when the publisher process has no matching local handlers for those types. A subclass uses its own `static eventKey` only when it declares one directly; otherwise its class name remains the subclass channel while base classes keep their own stable keys.
|
|
108
108
|
|
|
109
109
|
## Public API Overview
|
|
110
110
|
|
|
@@ -120,7 +120,7 @@ Handlers are discovered from singleton providers and controllers across imported
|
|
|
120
120
|
- `EventBus`, `EventPublishOptions`, `EventBusModuleOptions`, `EventType`: Type-only contracts for publishing, defaults, transports, and stable event keys.
|
|
121
121
|
- `EventBusLifecycleState`, `EventBusStatusAdapterInput`, `EventBusPlatformStatusSnapshot`: Status snapshot contracts.
|
|
122
122
|
|
|
123
|
-
Transport bootstrap subscribes once per unique event channel. `eventKey` controls the transport channel name when present. Invalid JSON transport messages are ignored.
|
|
123
|
+
Transport bootstrap subscribes once per unique event channel. `eventKey` controls the transport channel name when present. Invalid JSON transport messages are ignored, and inbound transport messages that arrive after shutdown starts are ignored before local handler dispatch.
|
|
124
124
|
|
|
125
125
|
## Runtime-Specific and Integration Subpaths
|
|
126
126
|
|
package/dist/service.d.ts
CHANGED
|
@@ -21,7 +21,8 @@ export declare class EventBusLifecycleService implements EventBus, OnApplication
|
|
|
21
21
|
private transportCloseFailures;
|
|
22
22
|
private transportPublishFailures;
|
|
23
23
|
private transportSubscribeFailures;
|
|
24
|
-
private
|
|
24
|
+
private shutdownDrainTimeouts;
|
|
25
|
+
private readonly activeDispatches;
|
|
25
26
|
private readonly transport;
|
|
26
27
|
constructor(runtimeContainer: Container, compiledModules: readonly CompiledModule[], logger: ApplicationLogger, moduleOptions: EventBusModuleOptions);
|
|
27
28
|
onApplicationBootstrap(): Promise<void>;
|
|
@@ -42,7 +43,10 @@ export declare class EventBusLifecycleService implements EventBus, OnApplication
|
|
|
42
43
|
publish(event: object, options?: EventPublishOptions): Promise<void>;
|
|
43
44
|
private executePublish;
|
|
44
45
|
private canPublishInCurrentLifecycle;
|
|
45
|
-
private
|
|
46
|
+
private drainActiveDispatches;
|
|
47
|
+
private trackActiveDispatch;
|
|
48
|
+
private awaitShutdownDrain;
|
|
49
|
+
private resolveShutdownDrainTimeoutMs;
|
|
46
50
|
private matchEventDescriptors;
|
|
47
51
|
private createInvocationTasks;
|
|
48
52
|
private createBackgroundInvocationTasks;
|
|
@@ -54,11 +58,14 @@ export declare class EventBusLifecycleService implements EventBus, OnApplication
|
|
|
54
58
|
private discoverHandlers;
|
|
55
59
|
private channelFromEventType;
|
|
56
60
|
private channelsForTransportPublish;
|
|
61
|
+
private eventTypeLineage;
|
|
57
62
|
private publishToTransport;
|
|
58
63
|
private logTransportPublishCancelledBeforeDispatch;
|
|
59
64
|
private logBoundedTransportPublishError;
|
|
60
65
|
private subscribeTransportChannels;
|
|
61
66
|
private subscribeTransportChannel;
|
|
67
|
+
private canDispatchIncomingTransportMessage;
|
|
68
|
+
private dispatchIncomingTransportMessage;
|
|
62
69
|
private preloadHandlerInstances;
|
|
63
70
|
private invokeHandlerWithBounds;
|
|
64
71
|
private logPublishCancelledBeforeDispatch;
|
package/dist/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,YAAY,CAAC;AACtD,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC3B,MAAM,iBAAiB,CAAC;AAMzB,OAAO,KAAK,EACV,QAAQ,EACR,qBAAqB,EAGrB,mBAAmB,EAEpB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,YAAY,CAAC;AACtD,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC3B,MAAM,iBAAiB,CAAC;AAMzB,OAAO,KAAK,EACV,QAAQ,EACR,qBAAqB,EAGrB,mBAAmB,EAEpB,MAAM,YAAY,CAAC;AAgEpB;;;;;GAKG;AACH,qBACa,wBAAyB,YAAW,QAAQ,EAAE,sBAAsB,EAAE,qBAAqB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AAC,qBAAqB;IAY7B,OAAO,CAAC,kBAAkB;YAQZ,gBAAgB;IAW9B,OAAO,CAAC,oBAAoB;IAY5B,OAAO,CAAC,2BAA2B;IAkBnC,OAAO,CAAC,gBAAgB;YAiBV,kBAAkB;IA8BhC,OAAO,CAAC,0CAA0C;IAOlD,OAAO,CAAC,+BAA+B;YAwBzB,0BAA0B;YAmB1B,yBAAyB;IAiCvC,OAAO,CAAC,mCAAmC;YAI7B,gCAAgC;YAmBhC,uBAAuB;YAUvB,uBAAuB;IAmBrC,OAAO,CAAC,iCAAiC;IAOzC,OAAO,CAAC,yBAAyB;YAwBnB,qBAAqB;IAuBnC,OAAO,CAAC,sBAAsB;IAqB9B,OAAO,CAAC,kBAAkB;IAiB1B,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,0BAA0B;IAyBlC,OAAO,CAAC,+BAA+B;IAevC,OAAO,CAAC,8BAA8B;IA4BtC,OAAO,CAAC,uBAAuB;IAe/B,OAAO,CAAC,mBAAmB;YAsCb,aAAa;YA4Bb,sBAAsB;CAsBrC"}
|
package/dist/service.js
CHANGED
|
@@ -10,6 +10,7 @@ import { APPLICATION_LOGGER, COMPILED_MODULES, RUNTIME_CONTAINER } from '@fluojs
|
|
|
10
10
|
import { getEventHandlerMetadataEntries } from './metadata.js';
|
|
11
11
|
import { createEventBusPlatformStatusSnapshot } from './status.js';
|
|
12
12
|
import { EVENT_BUS_OPTIONS } from './tokens.js';
|
|
13
|
+
const DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS = 5000;
|
|
13
14
|
function createIsolatedEvent(eventType, source) {
|
|
14
15
|
const clonedPayload = cloneWithFallback(source);
|
|
15
16
|
if (typeof clonedPayload !== 'object' || clonedPayload === null) {
|
|
@@ -64,7 +65,8 @@ class EventBusLifecycleService {
|
|
|
64
65
|
transportCloseFailures = 0;
|
|
65
66
|
transportPublishFailures = 0;
|
|
66
67
|
transportSubscribeFailures = 0;
|
|
67
|
-
|
|
68
|
+
shutdownDrainTimeouts = 0;
|
|
69
|
+
activeDispatches = new Set();
|
|
68
70
|
transport;
|
|
69
71
|
constructor(runtimeContainer, compiledModules, logger, moduleOptions) {
|
|
70
72
|
this.runtimeContainer = runtimeContainer;
|
|
@@ -86,8 +88,8 @@ class EventBusLifecycleService {
|
|
|
86
88
|
}
|
|
87
89
|
async onApplicationShutdown() {
|
|
88
90
|
this.lifecycleState = 'stopping';
|
|
89
|
-
if (this.
|
|
90
|
-
await this.
|
|
91
|
+
if (this.activeDispatches.size > 0) {
|
|
92
|
+
await this.drainActiveDispatches();
|
|
91
93
|
}
|
|
92
94
|
if (this.transport) {
|
|
93
95
|
try {
|
|
@@ -112,6 +114,8 @@ class EventBusLifecycleService {
|
|
|
112
114
|
return createEventBusPlatformStatusSnapshot({
|
|
113
115
|
handlersDiscovered: this.descriptors.length,
|
|
114
116
|
lifecycleState: this.lifecycleState,
|
|
117
|
+
shutdownDrainTimeoutMs: this.resolveShutdownDrainTimeoutMs(),
|
|
118
|
+
shutdownDrainTimeouts: this.shutdownDrainTimeouts,
|
|
115
119
|
subscribedChannels: this.subscribedChannels.size,
|
|
116
120
|
transportCloseFailures: this.transportCloseFailures,
|
|
117
121
|
transportConfigured: this.transport !== undefined,
|
|
@@ -133,13 +137,7 @@ class EventBusLifecycleService {
|
|
|
133
137
|
this.logger.warn(`EventBus.publish() was ignored because the event bus is ${this.lifecycleState}.`, 'EventBusLifecycleService');
|
|
134
138
|
return;
|
|
135
139
|
}
|
|
136
|
-
|
|
137
|
-
this.activePublishes.add(publishWorkflow);
|
|
138
|
-
try {
|
|
139
|
-
await publishWorkflow;
|
|
140
|
-
} finally {
|
|
141
|
-
this.activePublishes.delete(publishWorkflow);
|
|
142
|
-
}
|
|
140
|
+
await this.trackActiveDispatch(this.executePublish(event, options));
|
|
143
141
|
}
|
|
144
142
|
async executePublish(event, options) {
|
|
145
143
|
await this.ensureDiscovered();
|
|
@@ -166,8 +164,39 @@ class EventBusLifecycleService {
|
|
|
166
164
|
canPublishInCurrentLifecycle() {
|
|
167
165
|
return !['failed', 'stopped', 'stopping'].includes(this.lifecycleState);
|
|
168
166
|
}
|
|
169
|
-
async
|
|
170
|
-
|
|
167
|
+
async drainActiveDispatches() {
|
|
168
|
+
const activeDispatches = Array.from(this.activeDispatches);
|
|
169
|
+
const timeoutMs = this.resolveShutdownDrainTimeoutMs();
|
|
170
|
+
const drained = await this.awaitShutdownDrain(activeDispatches, timeoutMs);
|
|
171
|
+
if (!drained) {
|
|
172
|
+
this.shutdownDrainTimeouts += 1;
|
|
173
|
+
this.logger.warn(`Event bus shutdown drain exceeded ${String(timeoutMs)}ms with ${String(activeDispatches.length)} active dispatch workflow(s); continuing shutdown.`, 'EventBusLifecycleService');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async trackActiveDispatch(dispatchWorkflow) {
|
|
177
|
+
this.activeDispatches.add(dispatchWorkflow);
|
|
178
|
+
try {
|
|
179
|
+
await dispatchWorkflow;
|
|
180
|
+
} finally {
|
|
181
|
+
this.activeDispatches.delete(dispatchWorkflow);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async awaitShutdownDrain(activePublishes, timeoutMs) {
|
|
185
|
+
let timeoutId;
|
|
186
|
+
const timeout = new Promise(resolve => {
|
|
187
|
+
timeoutId = setTimeout(() => resolve(false), timeoutMs);
|
|
188
|
+
});
|
|
189
|
+
const drain = Promise.allSettled(activePublishes).then(() => true);
|
|
190
|
+
try {
|
|
191
|
+
return await Promise.race([drain, timeout]);
|
|
192
|
+
} finally {
|
|
193
|
+
if (timeoutId) {
|
|
194
|
+
clearTimeout(timeoutId);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
resolveShutdownDrainTimeoutMs() {
|
|
199
|
+
return this.normalizeTimeoutMs(this.moduleOptions.shutdown?.drainTimeoutMs) ?? DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS;
|
|
171
200
|
}
|
|
172
201
|
matchEventDescriptors(event) {
|
|
173
202
|
return this.descriptors.filter(descriptor => event instanceof descriptor.eventType);
|
|
@@ -237,7 +266,7 @@ class EventBusLifecycleService {
|
|
|
237
266
|
}
|
|
238
267
|
}
|
|
239
268
|
channelFromEventType(eventType) {
|
|
240
|
-
if (typeof eventType.eventKey === 'string') {
|
|
269
|
+
if (Object.hasOwn(eventType, 'eventKey') && typeof eventType.eventKey === 'string') {
|
|
241
270
|
const eventKey = eventType.eventKey.trim();
|
|
242
271
|
if (eventKey.length > 0) {
|
|
243
272
|
return eventKey;
|
|
@@ -247,6 +276,9 @@ class EventBusLifecycleService {
|
|
|
247
276
|
}
|
|
248
277
|
channelsForTransportPublish(event, descriptors) {
|
|
249
278
|
const channels = new Set();
|
|
279
|
+
for (const eventType of this.eventTypeLineage(event)) {
|
|
280
|
+
channels.add(this.channelFromEventType(eventType));
|
|
281
|
+
}
|
|
250
282
|
for (const descriptor of descriptors) {
|
|
251
283
|
channels.add(this.channelFromEventType(descriptor.eventType));
|
|
252
284
|
}
|
|
@@ -255,6 +287,18 @@ class EventBusLifecycleService {
|
|
|
255
287
|
}
|
|
256
288
|
return Array.from(channels);
|
|
257
289
|
}
|
|
290
|
+
eventTypeLineage(event) {
|
|
291
|
+
const eventTypes = [];
|
|
292
|
+
let prototype = Object.getPrototypeOf(event);
|
|
293
|
+
while (prototype && prototype !== Object.prototype) {
|
|
294
|
+
const constructor = prototype.constructor;
|
|
295
|
+
if (typeof constructor === 'function') {
|
|
296
|
+
eventTypes.push(constructor);
|
|
297
|
+
}
|
|
298
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
299
|
+
}
|
|
300
|
+
return eventTypes;
|
|
301
|
+
}
|
|
258
302
|
async publishToTransport(event, descriptors, publishOptions) {
|
|
259
303
|
if (!this.transport) {
|
|
260
304
|
return;
|
|
@@ -307,15 +351,14 @@ class EventBusLifecycleService {
|
|
|
307
351
|
async subscribeTransportChannel(channel, channelDescriptors) {
|
|
308
352
|
try {
|
|
309
353
|
await this.transport.subscribe(channel, async payload => {
|
|
354
|
+
if (!this.canDispatchIncomingTransportMessage()) {
|
|
355
|
+
this.logger.warn(`EventBusTransport message on channel "${channel}" was ignored because the event bus is ${this.lifecycleState}.`, 'EventBusLifecycleService');
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
310
358
|
if (channelDescriptors.length === 0) {
|
|
311
359
|
return;
|
|
312
360
|
}
|
|
313
|
-
|
|
314
|
-
signal: undefined,
|
|
315
|
-
timeoutMs: this.normalizeTimeoutMs(this.moduleOptions.publish?.timeoutMs),
|
|
316
|
-
waitForHandlers: this.moduleOptions.publish?.waitForHandlers ?? true
|
|
317
|
-
}));
|
|
318
|
-
await Promise.allSettled(invocationTasks);
|
|
361
|
+
await this.trackActiveDispatch(this.dispatchIncomingTransportMessage(channelDescriptors, payload));
|
|
319
362
|
});
|
|
320
363
|
this.subscribedChannels.add(channel);
|
|
321
364
|
} catch (error) {
|
|
@@ -324,6 +367,17 @@ class EventBusLifecycleService {
|
|
|
324
367
|
throw error;
|
|
325
368
|
}
|
|
326
369
|
}
|
|
370
|
+
canDispatchIncomingTransportMessage() {
|
|
371
|
+
return this.lifecycleState === 'ready';
|
|
372
|
+
}
|
|
373
|
+
async dispatchIncomingTransportMessage(channelDescriptors, payload) {
|
|
374
|
+
const invocationTasks = channelDescriptors.map(descriptor => this.invokeHandlerWithBounds(descriptor, createIsolatedEvent(descriptor.eventType, payload), {
|
|
375
|
+
signal: undefined,
|
|
376
|
+
timeoutMs: this.normalizeTimeoutMs(this.moduleOptions.publish?.timeoutMs),
|
|
377
|
+
waitForHandlers: this.moduleOptions.publish?.waitForHandlers ?? true
|
|
378
|
+
}));
|
|
379
|
+
await Promise.allSettled(invocationTasks);
|
|
380
|
+
}
|
|
327
381
|
async preloadHandlerInstances(descriptors) {
|
|
328
382
|
for (const descriptor of descriptors) {
|
|
329
383
|
if (this.handlerInstances.has(descriptor.token)) {
|
package/dist/status.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export type EventBusLifecycleState = 'created' | 'discovering' | 'ready' | 'stop
|
|
|
9
9
|
export interface EventBusStatusAdapterInput {
|
|
10
10
|
handlersDiscovered: number;
|
|
11
11
|
lifecycleState: EventBusLifecycleState;
|
|
12
|
+
shutdownDrainTimeoutMs: number;
|
|
13
|
+
shutdownDrainTimeouts: number;
|
|
12
14
|
subscribedChannels: number;
|
|
13
15
|
transportCloseFailures: number;
|
|
14
16
|
transportConfigured: boolean;
|
package/dist/status.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEvG;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE7G;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,sBAAsB,CAAC;IACvC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,wBAAwB,EAAE,MAAM,CAAC;IACjC,0BAA0B,EAAE,MAAM,CAAC;IACnC,sBAAsB,EAAE,OAAO,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,SAAS,EAAE,uBAAuB,CAAC;IACnC,MAAM,EAAE,oBAAoB,CAAC;IAC7B,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEvG;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE7G;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,sBAAsB,CAAC;IACvC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,wBAAwB,EAAE,MAAM,CAAC;IACjC,0BAA0B,EAAE,MAAM,CAAC;IACnC,sBAAsB,EAAE,OAAO,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,SAAS,EAAE,uBAAuB,CAAC;IACnC,MAAM,EAAE,oBAAoB,CAAC;IAC7B,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AA6FD;;;;;GAKG;AACH,wBAAgB,oCAAoC,CAAC,KAAK,EAAE,0BAA0B,GAAG,8BAA8B,CAuBtH"}
|
package/dist/status.js
CHANGED
|
@@ -71,9 +71,9 @@ function createHealth(input) {
|
|
|
71
71
|
status: 'degraded'
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
-
if (input.transportPublishFailures > 0 || input.transportSubscribeFailures > 0 || input.transportCloseFailures > 0) {
|
|
74
|
+
if (input.shutdownDrainTimeouts > 0 || input.transportPublishFailures > 0 || input.transportSubscribeFailures > 0 || input.transportCloseFailures > 0) {
|
|
75
75
|
return {
|
|
76
|
-
reason: 'Event bus
|
|
76
|
+
reason: 'Event bus reported recoverable runtime failures.',
|
|
77
77
|
status: 'degraded'
|
|
78
78
|
};
|
|
79
79
|
}
|
|
@@ -98,6 +98,8 @@ export function createEventBusPlatformStatusSnapshot(input) {
|
|
|
98
98
|
handlersDiscovered: input.handlersDiscovered,
|
|
99
99
|
lifecycleState: input.lifecycleState,
|
|
100
100
|
operationMode: resolveOperationMode(input),
|
|
101
|
+
shutdownDrainTimeoutMs: input.shutdownDrainTimeoutMs,
|
|
102
|
+
shutdownDrainTimeouts: input.shutdownDrainTimeouts,
|
|
101
103
|
subscribedChannels: input.subscribedChannels,
|
|
102
104
|
transportCloseFailures: input.transportCloseFailures,
|
|
103
105
|
transportConfigured: input.transportConfigured,
|
package/dist/types.d.ts
CHANGED
|
@@ -49,6 +49,10 @@ export interface EventBusModuleOptions {
|
|
|
49
49
|
timeoutMs?: number;
|
|
50
50
|
waitForHandlers?: boolean;
|
|
51
51
|
};
|
|
52
|
+
/** Shutdown drain policy. `drainTimeoutMs` defaults to 5000ms. */
|
|
53
|
+
shutdown?: {
|
|
54
|
+
drainTimeoutMs?: number;
|
|
55
|
+
};
|
|
52
56
|
/**
|
|
53
57
|
* Optional external transport adapter (e.g. Redis Pub/Sub).
|
|
54
58
|
* When provided, `publish()` fans out to the transport in addition to local handlers,
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE/D,qGAAqG;AACrG,MAAM,WAAW,SAAS,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM;IACvD,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,0CAA0C;AAC1C,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,SAAS,CAAC;CACtB;AA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C,EAAE;QACR,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B,CAAC;IACF,kEAAkE;IAClE,QAAQ,CAAC,EAAE;QACT,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;IACF;;;;OAIG;IACH,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B;AAED,+DAA+D;AAC/D,MAAM,WAAW,QAAQ;IACvB;;;;;;OAMG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE"}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"pubsub",
|
|
9
9
|
"in-process"
|
|
10
10
|
],
|
|
11
|
-
"version": "1.0.0-beta.
|
|
11
|
+
"version": "1.0.0-beta.7",
|
|
12
12
|
"private": false,
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"repository": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@fluojs/core": "^1.0.0-beta.
|
|
43
|
-
"@fluojs/di": "^1.0.0-beta.
|
|
42
|
+
"@fluojs/core": "^1.0.0-beta.6",
|
|
43
|
+
"@fluojs/di": "^1.0.0-beta.8",
|
|
44
44
|
"@fluojs/runtime": "^1.0.0-beta.12"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|