@@ -53,6 +53,7 @@ export type RunsReplicationServiceOptions = {
53
53
logLevel ?: LogLevel ;
54
54
tracer ?: Tracer ;
55
55
waitForAsyncInsert ?: boolean ;
56
+ insertStrategy ?: "insert" | "insert_async" ;
56
57
// Retry configuration for insert operations
57
58
insertMaxRetries ?: number ;
58
59
insertBaseDelayMs ?: number ;
@@ -90,6 +91,7 @@ export class RunsReplicationService {
90
91
private _insertMaxRetries : number ;
91
92
private _insertBaseDelayMs : number ;
92
93
private _insertMaxDelayMs : number ;
94
+ private _insertStrategy : "insert" | "insert_async" ;
93
95
94
96
public readonly events : EventEmitter < RunsReplicationServiceEvents > ;
95
97
@@ -101,6 +103,8 @@ export class RunsReplicationService {
101
103
102
104
this . _acknowledgeTimeoutMs = options . acknowledgeTimeoutMs ?? 1_000 ;
103
105
106
+ this . _insertStrategy = options . insertStrategy ?? "insert" ;
107
+
104
108
this . _replicationClient = new LogicalReplicationClient ( {
105
109
pgConfig : {
106
110
connectionString : options . pgConnectionUrl ,
@@ -598,15 +602,26 @@ export class RunsReplicationService {
598
602
return delay + jitter ;
599
603
}
600
604
605
+ #getClickhouseInsertSettings( ) {
606
+ if ( this . _insertStrategy === "insert" ) {
607
+ return { } ;
608
+ } else if ( this . _insertStrategy === "insert_async" ) {
609
+ return {
610
+ async_insert : 1 as const ,
611
+ async_insert_max_data_size : "1000000" ,
612
+ async_insert_busy_timeout_ms : 1000 ,
613
+ wait_for_async_insert : this . options . waitForAsyncInsert ? ( 1 as const ) : ( 0 as const ) ,
614
+ } ;
615
+ }
616
+ }
617
+
601
618
async #insertTaskRunInserts( taskRunInserts : TaskRunV2 [ ] , attempt : number ) {
602
619
return await startSpan ( this . _tracer , "insertTaskRunsInserts" , async ( span ) => {
603
620
const [ insertError , insertResult ] = await this . options . clickhouse . taskRuns . insert (
604
621
taskRunInserts ,
605
622
{
606
623
params : {
607
- clickhouse_settings : {
608
- wait_for_async_insert : this . options . waitForAsyncInsert ? 1 : 0 ,
609
- } ,
624
+ clickhouse_settings : this . #getClickhouseInsertSettings( ) ,
610
625
} ,
611
626
}
612
627
) ;
@@ -631,9 +646,7 @@ export class RunsReplicationService {
631
646
payloadInserts ,
632
647
{
633
648
params : {
634
- clickhouse_settings : {
635
- wait_for_async_insert : this . options . waitForAsyncInsert ? 1 : 0 ,
636
- } ,
649
+ clickhouse_settings : this . #getClickhouseInsertSettings( ) ,
637
650
} ,
638
651
}
639
652
) ;
0 commit comments