1
+ import { v4 as randomUUID } from 'uuid' ;
2
+
1
3
import ApiEndpoints from '../api-endpoints' ;
2
4
import { logger } from '../application-logger' ;
3
5
import { IAssignmentEvent , IAssignmentLogger } from '../assignment-logger' ;
@@ -20,7 +22,8 @@ import { EppoValue } from '../eppo_value';
20
22
import { Evaluator , FlagEvaluation , noneResult } from '../evaluator' ;
21
23
import ArrayBackedNamedEventQueue from '../events/array-backed-named-event-queue' ;
22
24
import { BoundedEventQueue } from '../events/bounded-event-queue' ;
23
- import NamedEventQueue from '../events/named-event-queue' ;
25
+ import EventDispatcher from '../events/event-dispatcher' ;
26
+ import NoOpEventDispatcher from '../events/no-op-event-dispatcher' ;
24
27
import {
25
28
FlagEvaluationDetailsBuilder ,
26
29
IFlagEvaluationDetails ,
@@ -76,8 +79,17 @@ export interface IContainerExperiment<T> {
76
79
treatmentVariationEntries : Array < T > ;
77
80
}
78
81
82
+ const DEFAULT_EVENT_DISPATCHER_CONFIG = {
83
+ // TODO: Replace with actual ingestion URL
84
+ ingestionUrl : 'https://example.com/events' ,
85
+ batchSize : 10 ,
86
+ flushIntervalMs : 10_000 ,
87
+ retryIntervalMs : 5_000 ,
88
+ maxRetries : 3 ,
89
+ } ;
90
+
79
91
export default class EppoClient {
80
- private readonly eventQueue : NamedEventQueue < unknown > ;
92
+ private readonly eventDispatcher : EventDispatcher ;
81
93
private readonly assignmentEventsQueue : BoundedEventQueue < IAssignmentEvent > =
82
94
newBoundedArrayEventQueue < IAssignmentEvent > ( 'assignments' ) ;
83
95
private readonly banditEventsQueue : BoundedEventQueue < IBanditEvent > =
@@ -98,23 +110,23 @@ export default class EppoClient {
98
110
private readonly evaluator = new Evaluator ( ) ;
99
111
100
112
constructor ( {
101
- eventQueue = new ArrayBackedNamedEventQueue ( 'events' ) ,
113
+ eventDispatcher = new NoOpEventDispatcher ( ) ,
102
114
isObfuscated = false ,
103
115
flagConfigurationStore,
104
116
banditVariationConfigurationStore,
105
117
banditModelConfigurationStore,
106
118
configurationRequestParameters,
107
119
} : {
108
- // Queue for arbitrary, application-level events (not to be confused with Eppo specific assignment
120
+ // Dispatcher for arbitrary, application-level events (not to be confused with Eppo specific assignment
109
121
// or bandit events). These events are application-specific and captures by EppoClient#track API.
110
- eventQueue ?: NamedEventQueue < unknown > ;
122
+ eventDispatcher ?: EventDispatcher ;
111
123
flagConfigurationStore : IConfigurationStore < Flag | ObfuscatedFlag > ;
112
124
banditVariationConfigurationStore ?: IConfigurationStore < BanditVariation [ ] > ;
113
125
banditModelConfigurationStore ?: IConfigurationStore < BanditParameters > ;
114
126
configurationRequestParameters ?: FlagConfigurationRequestParameters ;
115
127
isObfuscated ?: boolean ;
116
128
} ) {
117
- this . eventQueue = eventQueue ;
129
+ this . eventDispatcher = eventDispatcher ;
118
130
this . flagConfigurationStore = flagConfigurationStore ;
119
131
this . banditVariationConfigurationStore = banditVariationConfigurationStore ;
120
132
this . banditModelConfigurationStore = banditModelConfigurationStore ;
@@ -908,9 +920,10 @@ export default class EppoClient {
908
920
return result ;
909
921
}
910
922
923
+ /** TODO */
911
924
// noinspection JSUnusedGlobalSymbols
912
925
track ( event : unknown , params : Record < string , unknown > ) {
913
- this . eventQueue . push ( { event, params } ) ;
926
+ this . eventDispatcher . dispatch ( { id : randomUUID ( ) , data : event , params } ) ;
914
927
}
915
928
916
929
private newFlagEvaluationDetailsBuilder ( flagKey : string ) : FlagEvaluationDetailsBuilder {
@@ -928,7 +941,9 @@ export default class EppoClient {
928
941
return {
929
942
configFetchedAt : this . flagConfigurationStore . getConfigFetchedAt ( ) ?? '' ,
930
943
configPublishedAt : this . flagConfigurationStore . getConfigPublishedAt ( ) ?? '' ,
931
- configEnvironment : this . flagConfigurationStore . getEnvironment ( ) ?? { name : '' } ,
944
+ configEnvironment : this . flagConfigurationStore . getEnvironment ( ) ?? {
945
+ name : '' ,
946
+ } ,
932
947
} ;
933
948
}
934
949
@@ -1131,6 +1146,6 @@ export function checkValueTypeMatch(
1131
1146
}
1132
1147
}
1133
1148
1134
- export function newBoundedArrayEventQueue < T > ( name : string ) : BoundedEventQueue < T > {
1149
+ function newBoundedArrayEventQueue < T > ( name : string ) : BoundedEventQueue < T > {
1135
1150
return new BoundedEventQueue < T > ( new ArrayBackedNamedEventQueue < T > ( name ) ) ;
1136
1151
}
0 commit comments