@@ -20,17 +20,39 @@ export function resolveEventRepositoryForStore(store: string | undefined): IEven
20
20
export async function getEventRepository (
21
21
featureFlags : Record < string , unknown > | undefined
22
22
) : Promise < { repository : IEventRepository ; store : string } > {
23
- const taskEventRepository = await flags ( {
23
+ const taskEventRepository = await resolveTaskEventRepositoryFlag ( featureFlags ) ;
24
+
25
+ if ( taskEventRepository === "clickhouse" ) {
26
+ return { repository : clickhouseEventRepository , store : "clickhouse" } ;
27
+ }
28
+
29
+ return { repository : eventRepository , store : getTaskEventStore ( ) } ;
30
+ }
31
+
32
+ async function resolveTaskEventRepositoryFlag (
33
+ featureFlags : Record < string , unknown > | undefined
34
+ ) : Promise < "clickhouse" | "postgres" > {
35
+ const flag = await flags ( {
24
36
key : FEATURE_FLAG . taskEventRepository ,
25
37
defaultValue : env . EVENT_REPOSITORY_DEFAULT_STORE ,
26
38
overrides : featureFlags ,
27
39
} ) ;
28
40
29
- if ( taskEventRepository === "clickhouse" ) {
30
- return { repository : clickhouseEventRepository , store : "clickhouse" } ;
41
+ if ( flag === "clickhouse" ) {
42
+ return "clickhouse" ;
31
43
}
32
44
33
- return { repository : eventRepository , store : getTaskEventStore ( ) } ;
45
+ if ( env . EVENT_REPOSITORY_CLICKHOUSE_ROLLOUT_PERCENT ) {
46
+ const rolloutPercent = env . EVENT_REPOSITORY_CLICKHOUSE_ROLLOUT_PERCENT ;
47
+
48
+ const randomNumber = Math . random ( ) ;
49
+
50
+ if ( randomNumber < rolloutPercent ) {
51
+ return "clickhouse" ;
52
+ }
53
+ }
54
+
55
+ return flag ;
34
56
}
35
57
36
58
export async function recordRunDebugLog (
0 commit comments