@gravito/ripple 4.0.0 → 4.0.3
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 +26 -10
- package/dist/{ripple/src/OrbitRipple.d.ts → OrbitRipple.d.ts} +1 -0
- package/dist/{ripple/src/RippleServer.d.ts → RippleServer.d.ts} +32 -2
- package/dist/core/src/Application.d.ts +41 -0
- package/dist/core/src/ConfigManager.d.ts +39 -0
- package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
- package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
- package/dist/core/src/Container.d.ts +45 -0
- package/dist/core/src/ErrorHandler.d.ts +3 -0
- package/dist/core/src/HookManager.d.ts +104 -165
- package/dist/core/src/PlanetCore.d.ts +114 -1
- package/dist/core/src/RequestContext.d.ts +97 -0
- package/dist/core/src/Router.d.ts +32 -46
- package/dist/core/src/ServiceProvider.d.ts +22 -0
- package/dist/core/src/adapters/bun/BunContext.d.ts +10 -1
- package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +35 -0
- package/dist/core/src/adapters/bun/BunWebSocketHandler.d.ts +48 -0
- package/dist/core/src/adapters/bun/RadixRouter.d.ts +1 -0
- package/dist/core/src/adapters/bun/index.d.ts +7 -0
- package/dist/core/src/binary/BinaryUtils.d.ts +105 -0
- package/dist/core/src/binary/index.d.ts +5 -0
- package/dist/core/src/cli/queue-commands.d.ts +6 -0
- package/dist/core/src/compat/async-local-storage.d.ts +7 -0
- package/dist/core/src/compat/crypto.d.ts +6 -0
- package/dist/core/src/engine/AOTRouter.d.ts +16 -1
- package/dist/core/src/engine/FastContext.d.ts +42 -1
- package/dist/core/src/engine/Gravito.d.ts +13 -19
- package/dist/core/src/engine/MinimalContext.d.ts +23 -0
- package/dist/core/src/engine/analyzer.d.ts +92 -6
- package/dist/core/src/engine/types.d.ts +6 -0
- package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
- package/dist/core/src/events/BackpressureManager.d.ts +215 -0
- package/dist/core/src/events/DeadLetterQueue.d.ts +75 -1
- package/dist/core/src/events/EventBackend.d.ts +2 -1
- package/dist/core/src/events/EventOptions.d.ts +99 -4
- package/dist/core/src/events/EventPriorityQueue.d.ts +36 -175
- package/dist/core/src/events/FlowControlStrategy.d.ts +109 -0
- package/dist/core/src/events/MessageQueueBridge.d.ts +184 -0
- package/dist/core/src/events/PriorityEscalationManager.d.ts +82 -0
- package/dist/core/src/events/RetryScheduler.d.ts +104 -0
- package/dist/core/src/events/WorkerPool.d.ts +98 -0
- package/dist/core/src/events/WorkerPoolConfig.d.ts +153 -0
- package/dist/core/src/events/WorkerPoolMetrics.d.ts +65 -0
- package/dist/core/src/events/aggregation/AggregationWindow.d.ts +77 -0
- package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +135 -0
- package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +108 -0
- package/dist/core/src/events/aggregation/EventBatcher.d.ts +99 -0
- package/dist/core/src/events/aggregation/types.d.ts +117 -0
- package/dist/core/src/events/index.d.ts +18 -6
- package/dist/core/src/events/observability/OTelEventMetrics.d.ts +92 -0
- package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
- package/dist/core/src/events/observability/index.d.ts +4 -0
- package/dist/core/src/events/queue-core.d.ts +77 -0
- package/dist/core/src/events/task-executor.d.ts +51 -0
- package/dist/core/src/events/types.d.ts +59 -0
- package/dist/core/src/ffi/NativeAccelerator.d.ts +62 -0
- package/dist/core/src/ffi/NativeHasher.d.ts +139 -0
- package/dist/core/src/ffi/cbor-fallback.d.ts +96 -0
- package/dist/core/src/ffi/hash-fallback.d.ts +33 -0
- package/dist/core/src/ffi/index.d.ts +10 -0
- package/dist/core/src/ffi/types.d.ts +135 -0
- package/dist/core/src/health/HealthProvider.d.ts +67 -0
- package/dist/core/src/helpers/Str.d.ts +15 -0
- package/dist/core/src/hooks/ActionManager.d.ts +132 -0
- package/dist/core/src/hooks/AsyncDetector.d.ts +84 -0
- package/dist/core/src/hooks/FilterManager.d.ts +71 -0
- package/dist/core/src/hooks/MigrationWarner.d.ts +24 -0
- package/dist/core/src/hooks/dlq-operations.d.ts +60 -0
- package/dist/core/src/hooks/types.d.ts +107 -0
- package/dist/core/src/http/CookieJar.d.ts +2 -2
- package/dist/core/src/http/types.d.ts +43 -3
- package/dist/core/src/index.d.ts +504 -15
- package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
- package/dist/core/src/observability/contracts.d.ts +137 -0
- package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +36 -3
- package/dist/core/src/runtime/adapter-bun.d.ts +12 -0
- package/dist/core/src/runtime/adapter-deno.d.ts +12 -0
- package/dist/core/src/runtime/adapter-node.d.ts +12 -0
- package/dist/core/src/runtime/adapter-unknown.d.ts +13 -0
- package/dist/core/src/runtime/archive.d.ts +17 -0
- package/dist/core/src/runtime/compression.d.ts +21 -0
- package/dist/core/src/runtime/deep-equals.d.ts +56 -0
- package/dist/core/src/runtime/detection.d.ts +22 -0
- package/dist/core/src/runtime/escape.d.ts +34 -0
- package/dist/core/src/runtime/index.d.ts +44 -0
- package/dist/core/src/runtime/markdown.d.ts +44 -0
- package/dist/core/src/runtime/types.d.ts +436 -0
- package/dist/core/src/runtime-helpers.d.ts +67 -0
- package/dist/core/src/runtime.d.ts +10 -118
- package/dist/core/src/testing/HttpTester.d.ts +1 -0
- package/dist/core/src/transpiler-utils.d.ts +170 -0
- package/dist/{ripple/src/engines → engines}/BunEngine.d.ts +11 -0
- package/dist/engines/UWebSocketsEngine.d.ts +97 -0
- package/dist/engines/WsEngine.d.ts +69 -0
- package/dist/{ripple/src/engines → engines}/index.d.ts +4 -0
- package/dist/index.js +1 -7139
- package/dist/index.js.map +3 -69
- package/dist/{ripple/src/serializers → serializers}/ISerializer.d.ts +1 -1
- package/dist/{ripple/src/serializers → serializers}/JsonSerializer.d.ts +1 -1
- package/dist/{ripple/src/serializers → serializers}/ProtobufSerializer.d.ts +6 -3
- package/dist/{ripple/src/types.d.ts → types.d.ts} +11 -0
- package/package.json +7 -2
- package/dist/atlas/src/DB.d.ts +0 -301
- package/dist/atlas/src/OrbitAtlas.d.ts +0 -9
- package/dist/atlas/src/config/defineConfig.d.ts +0 -14
- package/dist/atlas/src/config/index.d.ts +0 -7
- package/dist/atlas/src/config/loadConfig.d.ts +0 -48
- package/dist/atlas/src/connection/Connection.d.ts +0 -108
- package/dist/atlas/src/connection/ConnectionManager.d.ts +0 -111
- package/dist/atlas/src/drivers/BunSQLDriver.d.ts +0 -32
- package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +0 -118
- package/dist/atlas/src/drivers/MongoDBDriver.d.ts +0 -36
- package/dist/atlas/src/drivers/MySQLDriver.d.ts +0 -66
- package/dist/atlas/src/drivers/PostgresDriver.d.ts +0 -83
- package/dist/atlas/src/drivers/RedisDriver.d.ts +0 -43
- package/dist/atlas/src/drivers/SQLiteDriver.d.ts +0 -45
- package/dist/atlas/src/drivers/types.d.ts +0 -260
- package/dist/atlas/src/errors/index.d.ts +0 -45
- package/dist/atlas/src/grammar/Grammar.d.ts +0 -342
- package/dist/atlas/src/grammar/MongoGrammar.d.ts +0 -47
- package/dist/atlas/src/grammar/MySQLGrammar.d.ts +0 -54
- package/dist/atlas/src/grammar/NullGrammar.d.ts +0 -35
- package/dist/atlas/src/grammar/PostgresGrammar.d.ts +0 -62
- package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +0 -32
- package/dist/atlas/src/index.d.ts +0 -67
- package/dist/atlas/src/migration/Migration.d.ts +0 -64
- package/dist/atlas/src/migration/MigrationRepository.d.ts +0 -65
- package/dist/atlas/src/migration/Migrator.d.ts +0 -110
- package/dist/atlas/src/migration/index.d.ts +0 -6
- package/dist/atlas/src/observability/AtlasMetrics.d.ts +0 -11
- package/dist/atlas/src/observability/AtlasObservability.d.ts +0 -15
- package/dist/atlas/src/observability/AtlasTracer.d.ts +0 -12
- package/dist/atlas/src/observability/index.d.ts +0 -9
- package/dist/atlas/src/orm/index.d.ts +0 -5
- package/dist/atlas/src/orm/model/DirtyTracker.d.ts +0 -121
- package/dist/atlas/src/orm/model/Model.d.ts +0 -449
- package/dist/atlas/src/orm/model/ModelRegistry.d.ts +0 -20
- package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +0 -136
- package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +0 -36
- package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +0 -87
- package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +0 -117
- package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +0 -64
- package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +0 -15
- package/dist/atlas/src/orm/model/concerns/index.d.ts +0 -12
- package/dist/atlas/src/orm/model/decorators.d.ts +0 -109
- package/dist/atlas/src/orm/model/errors.d.ts +0 -52
- package/dist/atlas/src/orm/model/index.d.ts +0 -10
- package/dist/atlas/src/orm/model/relationships.d.ts +0 -207
- package/dist/atlas/src/orm/model/types.d.ts +0 -12
- package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +0 -123
- package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +0 -54
- package/dist/atlas/src/orm/schema/index.d.ts +0 -6
- package/dist/atlas/src/orm/schema/types.d.ts +0 -85
- package/dist/atlas/src/query/Expression.d.ts +0 -60
- package/dist/atlas/src/query/NPlusOneDetector.d.ts +0 -10
- package/dist/atlas/src/query/QueryBuilder.d.ts +0 -573
- package/dist/atlas/src/query/clauses/GroupByClause.d.ts +0 -51
- package/dist/atlas/src/query/clauses/HavingClause.d.ts +0 -70
- package/dist/atlas/src/query/clauses/JoinClause.d.ts +0 -87
- package/dist/atlas/src/query/clauses/LimitClause.d.ts +0 -82
- package/dist/atlas/src/query/clauses/OrderByClause.d.ts +0 -69
- package/dist/atlas/src/query/clauses/SelectClause.d.ts +0 -71
- package/dist/atlas/src/query/clauses/WhereClause.d.ts +0 -167
- package/dist/atlas/src/query/clauses/index.d.ts +0 -11
- package/dist/atlas/src/schema/Blueprint.d.ts +0 -276
- package/dist/atlas/src/schema/ColumnDefinition.d.ts +0 -154
- package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +0 -37
- package/dist/atlas/src/schema/Schema.d.ts +0 -131
- package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +0 -23
- package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +0 -26
- package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +0 -28
- package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +0 -97
- package/dist/atlas/src/schema/grammars/index.d.ts +0 -7
- package/dist/atlas/src/schema/index.d.ts +0 -8
- package/dist/atlas/src/seed/Factory.d.ts +0 -90
- package/dist/atlas/src/seed/Seeder.d.ts +0 -28
- package/dist/atlas/src/seed/SeederRunner.d.ts +0 -74
- package/dist/atlas/src/seed/index.d.ts +0 -6
- package/dist/atlas/src/types/index.d.ts +0 -1100
- package/dist/atlas/src/utils/levenshtein.d.ts +0 -9
- package/dist/core/src/adapters/PhotonAdapter.d.ts +0 -171
- package/dist/core/src/adapters/photon-types.d.ts +0 -73
- package/dist/core/src/http/middleware/BodySizeLimit.d.ts +0 -16
- package/dist/core/src/http/middleware/Cors.d.ts +0 -24
- package/dist/core/src/http/middleware/Csrf.d.ts +0 -23
- package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +0 -28
- package/dist/core/src/http/middleware/SecurityHeaders.d.ts +0 -29
- package/dist/core/src/http/middleware/ThrottleRequests.d.ts +0 -18
- package/dist/core/src/instrumentation/index.d.ts +0 -35
- package/dist/core/src/instrumentation/opentelemetry.d.ts +0 -178
- package/dist/core/src/instrumentation/types.d.ts +0 -182
- package/dist/photon/src/index.d.ts +0 -84
- package/dist/photon/src/middleware/binary.d.ts +0 -31
- package/dist/photon/src/middleware/htmx.d.ts +0 -39
- package/dist/photon/src/middleware/ratelimit.d.ts +0 -157
- package/dist/photon/src/openapi.d.ts +0 -19
- /package/dist/{ripple/src/channels → channels}/Channel.d.ts +0 -0
- /package/dist/{ripple/src/channels → channels}/ChannelManager.d.ts +0 -0
- /package/dist/{ripple/src/channels → channels}/index.d.ts +0 -0
- /package/dist/{ripple/src/drivers → drivers}/LocalDriver.d.ts +0 -0
- /package/dist/{ripple/src/drivers → drivers}/NATSDriver.d.ts +0 -0
- /package/dist/{ripple/src/drivers → drivers}/RedisDriver.d.ts +0 -0
- /package/dist/{ripple/src/drivers → drivers}/index.d.ts +0 -0
- /package/dist/{ripple/src/engines → engines}/IRippleEngine.d.ts +0 -0
- /package/dist/{ripple/src/errors → errors}/RippleError.d.ts +0 -0
- /package/dist/{ripple/src/errors → errors}/index.d.ts +0 -0
- /package/dist/{ripple/src/events → events}/BroadcastEvent.d.ts +0 -0
- /package/dist/{ripple/src/events → events}/BroadcastManager.d.ts +0 -0
- /package/dist/{ripple/src/events → events}/Broadcaster.d.ts +0 -0
- /package/dist/{ripple/src/events → events}/index.d.ts +0 -0
- /package/dist/{ripple/src/health → health}/HealthChecker.d.ts +0 -0
- /package/dist/{ripple/src/health → health}/index.d.ts +0 -0
- /package/dist/{ripple/src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{ripple/src/logging → logging}/Logger.d.ts +0 -0
- /package/dist/{ripple/src/logging → logging}/index.d.ts +0 -0
- /package/dist/{ripple/src/middleware → middleware}/InterceptorManager.d.ts +0 -0
- /package/dist/{ripple/src/observability → observability}/RippleMetrics.d.ts +0 -0
- /package/dist/{ripple/src/reliability → reliability}/AckManager.d.ts +0 -0
- /package/dist/{ripple/src/serializers → serializers}/index.d.ts +0 -0
- /package/dist/{ripple/src/tracking → tracking}/ConnectionTracker.d.ts +0 -0
- /package/dist/{ripple/src/tracking → tracking}/SessionManager.d.ts +0 -0
- /package/dist/{ripple/src/tracking → tracking}/index.d.ts +0 -0
- /package/dist/{ripple/src/utils → utils}/MessageSerializer.d.ts +0 -0
- /package/dist/{ripple/src/utils → utils}/TokenBucket.d.ts +0 -0
- /package/dist/{ripple/src/utils → utils}/index.d.ts +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event aggregation manager (FS-102)
|
|
3
|
+
*
|
|
4
|
+
* Coordinates deduplication and batching for optimal event processing:
|
|
5
|
+
* - Event deduplication (pattern-based or idempotency-key based)
|
|
6
|
+
* - Micro-batching (time and size dual-trigger)
|
|
7
|
+
* - Backpressure-aware window adjustment
|
|
8
|
+
* - Complete statistics tracking
|
|
9
|
+
*
|
|
10
|
+
* Ported from: examples/flash-sale-fullstack/src/cache/events/EventAggregator.ts
|
|
11
|
+
*/
|
|
12
|
+
import type { BackpressureManager } from '../BackpressureManager';
|
|
13
|
+
import type { EventTask } from '../types';
|
|
14
|
+
import { AggregationWindow } from './AggregationWindow';
|
|
15
|
+
import { DeduplicationManager } from './DeduplicationManager';
|
|
16
|
+
import { EventBatcher } from './EventBatcher';
|
|
17
|
+
import type { AggregationConfig, AggregationStats } from './types';
|
|
18
|
+
/**
|
|
19
|
+
* Event aggregation manager.
|
|
20
|
+
*/
|
|
21
|
+
export declare class EventAggregationManager {
|
|
22
|
+
private deduplicator;
|
|
23
|
+
private batcher;
|
|
24
|
+
private window;
|
|
25
|
+
private config;
|
|
26
|
+
private backpressureManager?;
|
|
27
|
+
private submitToQueueFn?;
|
|
28
|
+
private disabled;
|
|
29
|
+
/**
|
|
30
|
+
* Create an event aggregation manager.
|
|
31
|
+
*/
|
|
32
|
+
constructor(config?: Partial<AggregationConfig>);
|
|
33
|
+
/**
|
|
34
|
+
* Set backpressure manager for window adjustment.
|
|
35
|
+
* FS-103:Also sets BackpressureManager on AggregationWindow for feedback loop.
|
|
36
|
+
*/
|
|
37
|
+
setBackpressureManager(backpressure: BackpressureManager): void;
|
|
38
|
+
/**
|
|
39
|
+
* Set the actual queue submission function.
|
|
40
|
+
*/
|
|
41
|
+
setSubmitToQueueFn(fn: (tasks: EventTask[]) => Promise<void>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Submit an event for aggregation.
|
|
44
|
+
*
|
|
45
|
+
* Returns true if accepted, false if rejected due to backpressure.
|
|
46
|
+
*/
|
|
47
|
+
submit(task: EventTask): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Submit multiple events.
|
|
50
|
+
*/
|
|
51
|
+
submitBatch(tasks: EventTask[]): Promise<number>;
|
|
52
|
+
/**
|
|
53
|
+
* Flush current batch to queue.
|
|
54
|
+
*/
|
|
55
|
+
flush(): Promise<EventTask[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Get aggregation statistics.
|
|
58
|
+
*/
|
|
59
|
+
getStats(): AggregationStats;
|
|
60
|
+
/**
|
|
61
|
+
* Reset statistics.
|
|
62
|
+
*/
|
|
63
|
+
resetStats(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Clear aggregation state.
|
|
66
|
+
*/
|
|
67
|
+
clear(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Check if there are pending events.
|
|
70
|
+
*/
|
|
71
|
+
hasPending(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Get pending event count.
|
|
74
|
+
*/
|
|
75
|
+
getPendingCount(): number;
|
|
76
|
+
/**
|
|
77
|
+
* Disable the aggregation manager.
|
|
78
|
+
*/
|
|
79
|
+
disable(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Enable the aggregation manager.
|
|
82
|
+
*/
|
|
83
|
+
enable(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Check if aggregation manager is enabled.
|
|
86
|
+
*/
|
|
87
|
+
isEnabled(): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Shutdown the aggregation manager.
|
|
90
|
+
*/
|
|
91
|
+
shutdown(): Promise<EventTask[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Submit deduplicated events to queue.
|
|
94
|
+
*/
|
|
95
|
+
private submitToQueue;
|
|
96
|
+
/**
|
|
97
|
+
* Get deduplication manager (for testing).
|
|
98
|
+
*/
|
|
99
|
+
__getDeduplicator(): DeduplicationManager;
|
|
100
|
+
/**
|
|
101
|
+
* Get event batcher (for testing).
|
|
102
|
+
*/
|
|
103
|
+
__getBatcher(): EventBatcher;
|
|
104
|
+
/**
|
|
105
|
+
* Get aggregation window (for testing).
|
|
106
|
+
*/
|
|
107
|
+
__getWindow(): AggregationWindow;
|
|
108
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event batcher for microbatching optimization (FS-102)
|
|
3
|
+
*
|
|
4
|
+
* Implements dual-trigger batching:
|
|
5
|
+
* - Time window trigger (default 50ms)
|
|
6
|
+
* - Batch size trigger (default 50 events)
|
|
7
|
+
*
|
|
8
|
+
* Expected improvements: 10-15% throughput increase
|
|
9
|
+
*
|
|
10
|
+
* Ported from: examples/flash-sale-fullstack/src/cache/events/BatchSubmitter.ts
|
|
11
|
+
*/
|
|
12
|
+
import type { EventTask } from '../types';
|
|
13
|
+
import type { BatchStats } from './types';
|
|
14
|
+
/**
|
|
15
|
+
* Event batcher for optimizing submission throughput.
|
|
16
|
+
*/
|
|
17
|
+
export declare class EventBatcher {
|
|
18
|
+
private queue;
|
|
19
|
+
private readonly batchSize;
|
|
20
|
+
private readonly flushIntervalMs;
|
|
21
|
+
private flushTimer;
|
|
22
|
+
private stats;
|
|
23
|
+
private submitFn;
|
|
24
|
+
/**
|
|
25
|
+
* Create an event batcher.
|
|
26
|
+
*
|
|
27
|
+
* @param batchSize - Batch size threshold (default 50)
|
|
28
|
+
* @param flushIntervalMs - Time window (ms, default 50)
|
|
29
|
+
* @param submitFn - Function to submit batches
|
|
30
|
+
*/
|
|
31
|
+
constructor(batchSize: number | undefined, flushIntervalMs: number | undefined, submitFn: (tasks: EventTask[]) => Promise<void>);
|
|
32
|
+
/**
|
|
33
|
+
* Enqueue an event.
|
|
34
|
+
*
|
|
35
|
+
* Automatically triggers flush if:
|
|
36
|
+
* 1. Batch size is reached
|
|
37
|
+
* 2. Time window expires
|
|
38
|
+
*/
|
|
39
|
+
enqueue(task: EventTask): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Enqueue multiple events.
|
|
42
|
+
*/
|
|
43
|
+
enqueueBatch(tasks: EventTask[]): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Flush queued events.
|
|
46
|
+
*
|
|
47
|
+
* @param auto - Whether this is an auto-triggered flush
|
|
48
|
+
* @returns Array of flushed events
|
|
49
|
+
*/
|
|
50
|
+
flush(auto?: boolean): Promise<EventTask[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Get statistics.
|
|
53
|
+
*/
|
|
54
|
+
getStats(): BatchStats;
|
|
55
|
+
/**
|
|
56
|
+
* Get pending event count.
|
|
57
|
+
*/
|
|
58
|
+
getPendingCount(): number;
|
|
59
|
+
/**
|
|
60
|
+
* Check if there are pending events.
|
|
61
|
+
*/
|
|
62
|
+
hasPending(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Clear the queue.
|
|
65
|
+
*/
|
|
66
|
+
clear(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Reset statistics.
|
|
69
|
+
*/
|
|
70
|
+
resetStats(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Stop the batcher and flush remaining events.
|
|
73
|
+
*/
|
|
74
|
+
stop(): Promise<EventTask[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Start time-window timer.
|
|
77
|
+
*/
|
|
78
|
+
private startTimer;
|
|
79
|
+
/**
|
|
80
|
+
* Clear timer.
|
|
81
|
+
*/
|
|
82
|
+
private clearTimer;
|
|
83
|
+
/**
|
|
84
|
+
* Adjust batch size.
|
|
85
|
+
*/
|
|
86
|
+
setBatchSize(newSize: number): void;
|
|
87
|
+
/**
|
|
88
|
+
* Adjust flush interval.
|
|
89
|
+
*/
|
|
90
|
+
setFlushInterval(_newIntervalMs: number): void;
|
|
91
|
+
/**
|
|
92
|
+
* Get batch size.
|
|
93
|
+
*/
|
|
94
|
+
getBatchSize(): number;
|
|
95
|
+
/**
|
|
96
|
+
* Get flush interval.
|
|
97
|
+
*/
|
|
98
|
+
getFlushInterval(): number;
|
|
99
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event aggregation and deduplication types (FS-102)
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
import { BackpressureState } from '../BackpressureManager';
|
|
6
|
+
/**
|
|
7
|
+
* Deduplication statistics.
|
|
8
|
+
*/
|
|
9
|
+
export interface DeduplicationStats {
|
|
10
|
+
/** Total events submitted */
|
|
11
|
+
totalEvents: number;
|
|
12
|
+
/** Events after deduplication */
|
|
13
|
+
deduplicatedEvents: number;
|
|
14
|
+
/** Events removed by deduplication */
|
|
15
|
+
removedCount: number;
|
|
16
|
+
/** Number of patterns aggregated */
|
|
17
|
+
patternsAggregated: number;
|
|
18
|
+
/** Deduplication rate (%) */
|
|
19
|
+
deduplicationRate: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Batch submission statistics.
|
|
23
|
+
*/
|
|
24
|
+
export interface BatchStats {
|
|
25
|
+
/** Total batches submitted */
|
|
26
|
+
totalBatches: number;
|
|
27
|
+
/** Total events submitted */
|
|
28
|
+
totalEvents: number;
|
|
29
|
+
/** Average batch size */
|
|
30
|
+
averageBatchSize: number;
|
|
31
|
+
/** Average batch latency (ms) */
|
|
32
|
+
averageBatchLatency: number;
|
|
33
|
+
/** Last flush timestamp */
|
|
34
|
+
lastFlushTime: number;
|
|
35
|
+
/** Pending events in queue */
|
|
36
|
+
pendingEvents: number;
|
|
37
|
+
/** Auto-triggered flushes */
|
|
38
|
+
autoFlushCount: number;
|
|
39
|
+
/** Manual flushes */
|
|
40
|
+
manualFlushCount: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Aggregation window statistics.
|
|
44
|
+
*/
|
|
45
|
+
export interface WindowStats {
|
|
46
|
+
/** Current window size (ms) */
|
|
47
|
+
currentWindowMs: number;
|
|
48
|
+
/** Minimum window size (ms) */
|
|
49
|
+
minWindowMs: number;
|
|
50
|
+
/** Maximum window size (ms) */
|
|
51
|
+
maxWindowMs: number;
|
|
52
|
+
/** Last window adjustment reason */
|
|
53
|
+
lastAdjustmentReason?: string;
|
|
54
|
+
/** Window adjustment count */
|
|
55
|
+
adjustmentCount: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Complete aggregation statistics.
|
|
59
|
+
*/
|
|
60
|
+
export interface AggregationStats {
|
|
61
|
+
deduplication: DeduplicationStats;
|
|
62
|
+
batching: BatchStats;
|
|
63
|
+
window: WindowStats;
|
|
64
|
+
timestamp: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Aggregation configuration options.
|
|
68
|
+
*/
|
|
69
|
+
export interface AggregationConfig {
|
|
70
|
+
/** Enable aggregation (default: false) */
|
|
71
|
+
enabled: boolean;
|
|
72
|
+
/** Window size in milliseconds (default: 200) */
|
|
73
|
+
windowMs?: number;
|
|
74
|
+
/** Batch size threshold (default: 50) */
|
|
75
|
+
batchSize?: number;
|
|
76
|
+
/** Deduplication strategy */
|
|
77
|
+
deduplication?: 'pattern' | 'idempotencyKey' | 'off';
|
|
78
|
+
/** Deduplication pattern (string or function) */
|
|
79
|
+
pattern?: string | ((args: unknown) => string);
|
|
80
|
+
/** Merge priority when deduplicating */
|
|
81
|
+
mergePriority?: 'highest' | 'earliest' | 'latest';
|
|
82
|
+
/** Enable background cleanup (default: true) */
|
|
83
|
+
enableCleanup?: boolean;
|
|
84
|
+
/** Cleanup interval (ms, default: 5 minutes) */
|
|
85
|
+
cleanupIntervalMs?: number;
|
|
86
|
+
/** TTL for deduplication entries (ms, default: 10 minutes) */
|
|
87
|
+
ttlMs?: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Default aggregation configuration.
|
|
91
|
+
*/
|
|
92
|
+
export declare const DEFAULT_AGGREGATION_CONFIG: Required<AggregationConfig>;
|
|
93
|
+
/**
|
|
94
|
+
* Priority order for merge decisions.
|
|
95
|
+
*/
|
|
96
|
+
export declare const PRIORITY_ORDER: Record<string, number>;
|
|
97
|
+
/**
|
|
98
|
+
* Backpressure-aware window configuration.
|
|
99
|
+
*/
|
|
100
|
+
export interface WindowAdjustmentConfig {
|
|
101
|
+
/** Window for NORMAL backpressure state */
|
|
102
|
+
normalMs: number;
|
|
103
|
+
/** Window for WARNING backpressure state */
|
|
104
|
+
warningMs: number;
|
|
105
|
+
/** Window for CRITICAL backpressure state */
|
|
106
|
+
criticalMs: number;
|
|
107
|
+
/** Window for OVERFLOW backpressure state */
|
|
108
|
+
overflowMs: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Default window adjustment configuration based on backpressure.
|
|
112
|
+
*/
|
|
113
|
+
export declare const DEFAULT_WINDOW_ADJUSTMENT: WindowAdjustmentConfig;
|
|
114
|
+
/**
|
|
115
|
+
* Get suggested window size based on backpressure state.
|
|
116
|
+
*/
|
|
117
|
+
export declare function getSuggestedWindow(state: BackpressureState, config?: WindowAdjustmentConfig): number;
|
|
@@ -2,13 +2,25 @@
|
|
|
2
2
|
* Event system exports for async event dispatch.
|
|
3
3
|
* @packageDocumentation
|
|
4
4
|
*/
|
|
5
|
-
export type { CircuitBreakerOptions } from './CircuitBreaker';
|
|
6
|
-
export { CircuitBreaker, CircuitBreakerState } from './CircuitBreaker';
|
|
7
|
-
export type { DLQEntry, DLQFilter } from './DeadLetterQueue';
|
|
8
|
-
export { DeadLetterQueue } from './DeadLetterQueue';
|
|
9
5
|
export * from './EventBackend';
|
|
10
6
|
export type { EventOptions } from './EventOptions';
|
|
11
7
|
export { DEFAULT_EVENT_OPTIONS } from './EventOptions';
|
|
12
|
-
export { EventPriorityQueue } from './EventPriorityQueue';
|
|
13
|
-
export * from './observability';
|
|
14
8
|
export type { BackpressureStrategy, EventQueueConfig, EventTask } from './types';
|
|
9
|
+
export type { BackpressureConfig, BackpressureDecision, BackpressureMetricsSnapshot, } from './BackpressureManager';
|
|
10
|
+
export { BackpressureManager, BackpressureState } from './BackpressureManager';
|
|
11
|
+
export type { CircuitBreakerMetrics, CircuitBreakerMetricsRecorder, CircuitBreakerOptions, } from './CircuitBreaker';
|
|
12
|
+
export { CircuitBreaker, CircuitBreakerState } from './CircuitBreaker';
|
|
13
|
+
export type { DLQEntry, DLQEntryCallback, DLQEntrySource, DLQFilter } from './DeadLetterQueue';
|
|
14
|
+
export { DeadLetterQueue } from './DeadLetterQueue';
|
|
15
|
+
export { EventPriorityQueue } from './EventPriorityQueue';
|
|
16
|
+
export * from './FlowControlStrategy';
|
|
17
|
+
export { IdempotencyCache } from './IdempotencyCache';
|
|
18
|
+
export { MessageQueueBridge } from './MessageQueueBridge';
|
|
19
|
+
export type { PriorityStatistics } from './PriorityEscalationManager';
|
|
20
|
+
export { PriorityEscalationManager } from './PriorityEscalationManager';
|
|
21
|
+
export type { RetrySchedulerConfig } from './RetryScheduler';
|
|
22
|
+
export { RetryScheduler } from './RetryScheduler';
|
|
23
|
+
export type { DeadLetterDecision, MultiPriorityQueueDepth, WindowAdjustment } from './types';
|
|
24
|
+
export { WorkerPool } from './WorkerPool';
|
|
25
|
+
export type { WorkerPoolConfig, WorkerPoolStats, WorkerStats } from './WorkerPoolConfig';
|
|
26
|
+
export { WorkerPoolMetrics } from './WorkerPoolMetrics';
|
|
@@ -18,6 +18,7 @@ import type { CircuitBreakerMetricsRecorder } from '../CircuitBreaker';
|
|
|
18
18
|
* Returns the current queue depths for each priority level.
|
|
19
19
|
*/
|
|
20
20
|
export type QueueDepthCallback = () => {
|
|
21
|
+
critical: number;
|
|
21
22
|
high: number;
|
|
22
23
|
normal: number;
|
|
23
24
|
low: number;
|
|
@@ -72,6 +73,16 @@ export declare class OTelEventMetrics implements CircuitBreakerMetricsRecorder {
|
|
|
72
73
|
private readonly cbSuccessesCounter;
|
|
73
74
|
private readonly cbTransitionsCounter;
|
|
74
75
|
private readonly cbOpenDurationHistogram;
|
|
76
|
+
private readonly backpressureRejectionsCounter;
|
|
77
|
+
private readonly backpressureStateGauge;
|
|
78
|
+
private readonly backpressureDegradationsCounter;
|
|
79
|
+
private backpressureStateValue;
|
|
80
|
+
private readonly dlqEntriesCounter;
|
|
81
|
+
private readonly dlqDepthGauge;
|
|
82
|
+
private readonly dlqRequeueCounter;
|
|
83
|
+
private readonly retryAttemptsCounter;
|
|
84
|
+
private dlqDepthCallback?;
|
|
85
|
+
private readonly priorityEscalationCounter;
|
|
75
86
|
private queueDepthCallback?;
|
|
76
87
|
private circuitBreakerStateCallbacks;
|
|
77
88
|
private recordedCircuitBreakerStates;
|
|
@@ -237,4 +248,85 @@ export declare class OTelEventMetrics implements CircuitBreakerMetricsRecorder {
|
|
|
237
248
|
* Clear all circuit breaker state callbacks.
|
|
238
249
|
*/
|
|
239
250
|
clearCircuitBreakerCallbacks(): void;
|
|
251
|
+
/**
|
|
252
|
+
* Record a backpressure rejection event.
|
|
253
|
+
*
|
|
254
|
+
* @param eventName - Event name
|
|
255
|
+
* @param priority - Event priority
|
|
256
|
+
* @param reason - Rejection reason
|
|
257
|
+
*/
|
|
258
|
+
recordBackpressureRejection(eventName: string, priority: string, reason: string): void;
|
|
259
|
+
/**
|
|
260
|
+
* Record a backpressure state change event.
|
|
261
|
+
*
|
|
262
|
+
* @param state - New backpressure state (NORMAL, WARNING, CRITICAL, OVERFLOW)
|
|
263
|
+
*/
|
|
264
|
+
recordBackpressureState(state: string): void;
|
|
265
|
+
/**
|
|
266
|
+
* Record a backpressure degradation event.
|
|
267
|
+
*
|
|
268
|
+
* @param eventName - Event name
|
|
269
|
+
* @param fromPriority - Original priority
|
|
270
|
+
* @param toPriority - Degraded priority
|
|
271
|
+
*/
|
|
272
|
+
recordBackpressureDegradation(eventName: string, fromPriority: string, toPriority: string): void;
|
|
273
|
+
/**
|
|
274
|
+
* Record an event added to Dead Letter Queue.
|
|
275
|
+
*
|
|
276
|
+
* @param eventName - Event name
|
|
277
|
+
* @param source - Source of DLQ entry (retry_exhausted, circuit_breaker, backpressure_overflow)
|
|
278
|
+
*/
|
|
279
|
+
recordDLQEntry(eventName: string, source: string): void;
|
|
280
|
+
/**
|
|
281
|
+
* Set the callback for DLQ depth observable gauge.
|
|
282
|
+
*
|
|
283
|
+
* @param callback - Function returning current DLQ depth
|
|
284
|
+
*/
|
|
285
|
+
setDLQDepthCallback(callback: () => number): void;
|
|
286
|
+
/**
|
|
287
|
+
* Record a DLQ requeue attempt.
|
|
288
|
+
*
|
|
289
|
+
* @param eventName - Event name
|
|
290
|
+
* @param result - Result of requeue (success or failure)
|
|
291
|
+
*/
|
|
292
|
+
recordDLQRequeue(eventName: string, result: 'success' | 'failure'): void;
|
|
293
|
+
/**
|
|
294
|
+
* Record an event retry attempt.
|
|
295
|
+
*
|
|
296
|
+
* @param eventName - Event name
|
|
297
|
+
* @param attemptNumber - Attempt number
|
|
298
|
+
*/
|
|
299
|
+
recordRetryAttempt(eventName: string, attemptNumber: number): void;
|
|
300
|
+
/**
|
|
301
|
+
* Record a priority escalation event.
|
|
302
|
+
*
|
|
303
|
+
* @param eventName - Event name
|
|
304
|
+
* @param fromPriority - Original priority
|
|
305
|
+
* @param toPriority - Escalated priority
|
|
306
|
+
*/
|
|
307
|
+
recordPriorityEscalation(eventName: string, fromPriority: string, toPriority: string): void;
|
|
308
|
+
/**
|
|
309
|
+
* Record event deduplication (FS-102).
|
|
310
|
+
*
|
|
311
|
+
* @param eventName - Event name
|
|
312
|
+
* @param deduplicatedCount - Number of events after deduplication
|
|
313
|
+
* @param totalCount - Total number of events before deduplication
|
|
314
|
+
*/
|
|
315
|
+
recordDeduplication(eventName: string, deduplicatedCount: number, totalCount: number): void;
|
|
316
|
+
/**
|
|
317
|
+
* Record batch submission (FS-102).
|
|
318
|
+
*
|
|
319
|
+
* @param eventName - Event name
|
|
320
|
+
* @param batchSize - Size of submitted batch
|
|
321
|
+
* @param windowMs - Aggregation window size
|
|
322
|
+
*/
|
|
323
|
+
recordBatch(eventName: string, batchSize: number, windowMs: number): void;
|
|
324
|
+
/**
|
|
325
|
+
* Record window adjustment (FS-102).
|
|
326
|
+
*
|
|
327
|
+
* @param oldWindowMs - Previous window size
|
|
328
|
+
* @param newWindowMs - New window size
|
|
329
|
+
* @param reason - Adjustment reason
|
|
330
|
+
*/
|
|
331
|
+
recordWindowAdjustment(oldWindowMs: number, newWindowMs: number, reason: string): void;
|
|
240
332
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker Pool Metrics Recorder for OpenTelemetry integration.
|
|
3
|
+
*
|
|
4
|
+
* Tracks Worker Pool statistics and emits OpenTelemetry metrics.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
import type { Meter } from '@opentelemetry/api';
|
|
9
|
+
/**
|
|
10
|
+
* Worker job status for metrics.
|
|
11
|
+
*/
|
|
12
|
+
export declare enum WorkerJobStatus {
|
|
13
|
+
COMPLETED = "completed",
|
|
14
|
+
FAILED = "failed"
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Stream Worker Metrics Recorder.
|
|
18
|
+
*
|
|
19
|
+
* Collects and records metrics related to Worker Pool execution:
|
|
20
|
+
* - Pool size and utilization
|
|
21
|
+
* - Job execution duration
|
|
22
|
+
* - Job success/failure counts
|
|
23
|
+
* - Queue depth
|
|
24
|
+
*/
|
|
25
|
+
export declare class StreamWorkerMetrics {
|
|
26
|
+
private meter;
|
|
27
|
+
private jobDurationHistogram?;
|
|
28
|
+
private jobCounterCompleted?;
|
|
29
|
+
constructor(meter: Meter);
|
|
30
|
+
/**
|
|
31
|
+
* Initialize OpenTelemetry metrics.
|
|
32
|
+
*/
|
|
33
|
+
private initializeMetrics;
|
|
34
|
+
/**
|
|
35
|
+
* Record job execution duration.
|
|
36
|
+
*
|
|
37
|
+
* @param durationSeconds - Duration in seconds
|
|
38
|
+
* @param status - Job status (completed or failed)
|
|
39
|
+
* @param queue - Queue name
|
|
40
|
+
*/
|
|
41
|
+
recordJobDuration(durationSeconds: number, status: WorkerJobStatus, queue?: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Record pool size change.
|
|
44
|
+
*
|
|
45
|
+
* @param poolSize - Current pool size
|
|
46
|
+
* @param callback - Optional callback to fetch pool size dynamically
|
|
47
|
+
*/
|
|
48
|
+
setPoolSizeProvider(callback: () => number): void;
|
|
49
|
+
private poolSizeCallback?;
|
|
50
|
+
/**
|
|
51
|
+
* Get current pool size.
|
|
52
|
+
*/
|
|
53
|
+
getPoolSize(): number;
|
|
54
|
+
/**
|
|
55
|
+
* Record queue depth change.
|
|
56
|
+
*
|
|
57
|
+
* @param depth - Current queue depth
|
|
58
|
+
* @param callback - Optional callback to fetch queue depth dynamically
|
|
59
|
+
*/
|
|
60
|
+
setQueueDepthProvider(callback: () => number): void;
|
|
61
|
+
private queueDepthCallback?;
|
|
62
|
+
/**
|
|
63
|
+
* Get current queue depth.
|
|
64
|
+
*/
|
|
65
|
+
getQueueDepth(): number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Worker Metrics Recorder interface for dependency injection.
|
|
69
|
+
*/
|
|
70
|
+
export interface WorkerMetricsRecorder {
|
|
71
|
+
recordJobDuration(durationSeconds: number, status: WorkerJobStatus, queue?: string): void;
|
|
72
|
+
setPoolSizeProvider(callback: () => number): void;
|
|
73
|
+
setQueueDepthProvider(callback: () => number): void;
|
|
74
|
+
getPoolSize(): number;
|
|
75
|
+
getQueueDepth(): number;
|
|
76
|
+
}
|
|
@@ -18,3 +18,7 @@ export { type ObservabilityConfig, ObservableHookManager } from './ObservableHoo
|
|
|
18
18
|
* @public
|
|
19
19
|
*/
|
|
20
20
|
export { OTelEventMetrics, type QueueDepthCallback } from './OTelEventMetrics';
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export { StreamWorkerMetrics, WorkerJobStatus, type WorkerMetricsRecorder, } from './StreamWorkerMetrics';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { BackpressureManager } from './BackpressureManager';
|
|
2
|
+
import type { DeadLetterQueue } from './DeadLetterQueue';
|
|
3
|
+
import type { OTelEventMetrics } from './observability/OTelEventMetrics';
|
|
4
|
+
import { type PriorityStatistics } from './PriorityEscalationManager';
|
|
5
|
+
import type { BackpressureStrategy, EventQueueConfig, EventTask, MultiPriorityQueueDepth } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Result of an enqueue operation.
|
|
8
|
+
*
|
|
9
|
+
* - `{ status: 'queued', id }` - Task successfully queued
|
|
10
|
+
* - `{ status: 'dropped' }` - Task dropped due to backpressure
|
|
11
|
+
* - `{ status: 'delayed', id, delayMs }` - Task should be re-enqueued after delayMs
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export type EnqueueResult = {
|
|
16
|
+
status: 'queued';
|
|
17
|
+
id: string;
|
|
18
|
+
} | {
|
|
19
|
+
status: 'dropped';
|
|
20
|
+
} | {
|
|
21
|
+
status: 'delayed';
|
|
22
|
+
id: string;
|
|
23
|
+
delayMs: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Priority queue core: manages event task queues and backpressure.
|
|
27
|
+
*
|
|
28
|
+
* Handles enqueueing, dequeuing, backpressure logic, and priority escalation.
|
|
29
|
+
* This class is used internally by EventPriorityQueue as a composition target.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export declare class QueueCore {
|
|
34
|
+
criticalPriority: EventTask[];
|
|
35
|
+
highPriority: EventTask[];
|
|
36
|
+
normalPriority: EventTask[];
|
|
37
|
+
lowPriority: EventTask[];
|
|
38
|
+
processingPartitions: Set<string>;
|
|
39
|
+
private taskIdCounter;
|
|
40
|
+
private dlq?;
|
|
41
|
+
private otelEventMetrics?;
|
|
42
|
+
private backpressureManager?;
|
|
43
|
+
private priorityStats?;
|
|
44
|
+
private config;
|
|
45
|
+
constructor(config?: EventQueueConfig);
|
|
46
|
+
setDeadLetterQueue(dlq: DeadLetterQueue): void;
|
|
47
|
+
setOTelEventMetrics(metrics: OTelEventMetrics): void;
|
|
48
|
+
setPriorityStatistics(stats: PriorityStatistics): void;
|
|
49
|
+
getPriorityStatistics(): PriorityStatistics | undefined;
|
|
50
|
+
getBackpressureManager(): BackpressureManager | undefined;
|
|
51
|
+
getConfig(): EventQueueConfig;
|
|
52
|
+
getDLQ(): DeadLetterQueue | undefined;
|
|
53
|
+
createTaskId(): string;
|
|
54
|
+
/**
|
|
55
|
+
* Enqueue a task into the appropriate priority queue.
|
|
56
|
+
* Applies priority escalation and backpressure logic.
|
|
57
|
+
*/
|
|
58
|
+
enqueue(task: EventTask): EnqueueResult;
|
|
59
|
+
/**
|
|
60
|
+
* Dequeue the next task based on priority and partition ordering.
|
|
61
|
+
* Priority order: CRITICAL > HIGH > NORMAL > LOW
|
|
62
|
+
*/
|
|
63
|
+
dequeue(): EventTask | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Re-enqueue a task for retry.
|
|
66
|
+
*/
|
|
67
|
+
enqueueRetry(task: EventTask): void;
|
|
68
|
+
getDepth(): number;
|
|
69
|
+
getDepthByPriority(priority: 'critical' | 'high' | 'normal' | 'low'): number;
|
|
70
|
+
getQueueDepthByPriority(): MultiPriorityQueueDepth;
|
|
71
|
+
clear(): void;
|
|
72
|
+
syncBackpressure(): void;
|
|
73
|
+
private handleBackpressure;
|
|
74
|
+
private dropOldest;
|
|
75
|
+
private dequeueFromPriority;
|
|
76
|
+
}
|
|
77
|
+
export type { BackpressureStrategy, EventQueueConfig, EventTask };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Span } from '@opentelemetry/api';
|
|
2
|
+
import { CircuitBreaker } from './CircuitBreaker';
|
|
3
|
+
import type { DeadLetterQueue } from './DeadLetterQueue';
|
|
4
|
+
import type { EventOptions } from './EventOptions';
|
|
5
|
+
import type { EventMetrics } from './observability/EventMetrics';
|
|
6
|
+
import type { EventTracing } from './observability/EventTracing';
|
|
7
|
+
import type { OTelEventMetrics } from './observability/OTelEventMetrics';
|
|
8
|
+
import type { RetryScheduler } from './RetryScheduler';
|
|
9
|
+
import type { EventTask } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Executes event tasks with circuit breaker protection, retry logic,
|
|
12
|
+
* exponential backoff, DLQ integration, and distributed tracing.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare class TaskExecutor {
|
|
17
|
+
private eventCircuitBreakers;
|
|
18
|
+
private eventMetrics?;
|
|
19
|
+
private otelEventMetrics?;
|
|
20
|
+
private eventTracing?;
|
|
21
|
+
private currentDispatchSpan?;
|
|
22
|
+
private retryScheduler?;
|
|
23
|
+
private dlq?;
|
|
24
|
+
private persistentDLQHandler?;
|
|
25
|
+
private enqueueRetryFn?;
|
|
26
|
+
setDeadLetterQueue(dlq: DeadLetterQueue): void;
|
|
27
|
+
setPersistentDLQHandler(handler: (hook: string, args: unknown, options: EventOptions, error: Error, retryCount: number, firstFailedAt: number) => Promise<void>): void;
|
|
28
|
+
setEventMetrics(metrics: EventMetrics): void;
|
|
29
|
+
setOTelEventMetrics(metrics: OTelEventMetrics): void;
|
|
30
|
+
setEventTracing(tracing: EventTracing): void;
|
|
31
|
+
setCurrentDispatchSpan(span: Span | undefined): void;
|
|
32
|
+
getCurrentDispatchSpan(): Span | undefined;
|
|
33
|
+
setRetryScheduler(scheduler: RetryScheduler): void;
|
|
34
|
+
getRetryScheduler(): RetryScheduler | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Set the callback to use when re-enqueueing a task after a retry delay.
|
|
37
|
+
*/
|
|
38
|
+
setEnqueueRetryFn(fn: (task: EventTask) => void): void;
|
|
39
|
+
getCircuitBreaker(hook: string): CircuitBreaker | undefined;
|
|
40
|
+
getCircuitBreakers(): Map<string, CircuitBreaker>;
|
|
41
|
+
resetCircuitBreaker(hook: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Execute an event task by running all its callbacks.
|
|
44
|
+
* Implements circuit breaker protection, retry logic, and DLQ integration.
|
|
45
|
+
*/
|
|
46
|
+
executeTask(task: EventTask, processingPartitions: Set<string>): Promise<void>;
|
|
47
|
+
private sendToDLQ;
|
|
48
|
+
private getOrCreateEventCircuitBreaker;
|
|
49
|
+
private calculateRetryDelay;
|
|
50
|
+
private executeWithTimeout;
|
|
51
|
+
}
|