@@ -61,60 +61,60 @@ type Logging() =
6161 let logEventIsMetric x = Serilog.Filters.Matching.WithProperty( Metrics.PropertyTag) .Invoke x
6262 configuration.Sinks( configureMetricsSinks, Sinks.console verboseConsole, ?isMetric = if verboseStore then None else Some logEventIsMetric)
6363
64- module CosmosStoreConnector =
65-
66- let private get ( role : string ) ( client : Microsoft.Azure.Cosmos.CosmosClient ) databaseId containerId =
67- Log.Information( " CosmosDB {role} {database}/{container}" , role, databaseId, containerId)
68- client.GetDatabase( databaseId) .GetContainer( containerId)
69- let getSource = get " Source"
70- let getLeases = get " Leases"
71- let createMonitoredAndLeases client databaseId containerId auxContainerId =
72- getSource client databaseId containerId, getLeases client databaseId auxContainerId
73-
74- type Equinox.CosmosStore.CosmosStoreContext with
75-
76- member x.LogConfiguration ( role , databaseId : string , containerId : string ) =
77- Log.Information( " CosmosStore {role:l} {database}/{container} Tip maxEvents {maxEvents} maxSize {maxJsonLen} Query maxItems {queryMaxItems}" ,
78- role, databaseId, containerId, x.TipOptions.MaxEvents, x.TipOptions.MaxJsonLength, x.QueryOptions.MaxItems)
79-
80- type Equinox.CosmosStore.CosmosStoreClient with
81-
82- member x.CreateContext ( role : string , databaseId , containerId , tipMaxEvents , ? queryMaxItems , ? tipMaxJsonLength , ? skipLog ) =
83- let c = Equinox.CosmosStore.CosmosStoreContext( x, databaseId, containerId, tipMaxEvents, ?queryMaxItems = queryMaxItems, ?tipMaxJsonLength = tipMaxJsonLength)
84- if skipLog = Some true then () else c.LogConfiguration( role, databaseId, containerId)
85- c
86-
87- type Equinox.CosmosStore.CosmosStoreConnector with
88-
89- member private x.LogConfiguration ( role , databaseId : string , containers : string []) =
90- let o = x.Options
91- let timeout , retries429 , timeout429 = o.RequestTimeout, o.MaxRetryAttemptsOnRateLimitedRequests, o.MaxRetryWaitTimeOnRateLimitedRequests
92- Log.Information( " CosmosDB {role} {mode} {endpointUri} {database}/{containers} timeout {timeout}s Retries {retries}<{maxRetryWaitTime}s" ,
93- role, o.ConnectionMode, x.Endpoint, databaseId, containers, timeout.TotalSeconds, retries429, let t = timeout429.Value in t.TotalSeconds)
94- member private x.CreateAndInitialize ( role , databaseId , containers ) =
95- x.LogConfiguration( role, databaseId, containers)
96- x.CreateAndInitialize( databaseId, containers)
97- member private x.Connect ( role , databaseId , containers ) =
98- x.LogConfiguration( role, databaseId, containers)
99- x.Connect( databaseId, containers)
100-
101- // NOTE uses CreateUninitialized as the Database/Container may not actually exist yet
102- member x.CreateLeasesContainer ( databaseId , auxContainerId ) =
103- x.LogConfiguration( " Feed" , databaseId, [| auxContainerId |])
104- let client = x.CreateUninitialized()
105- CosmosStoreConnector.getLeases client databaseId auxContainerId
106-
107- member x.ConnectFeed ( databaseId , containerId , auxContainerId ) = async {
108- let! cosmosClient = x.CreateAndInitialize( " Feed" , databaseId, [| containerId; auxContainerId |])
109- return CosmosStoreConnector.createMonitoredAndLeases cosmosClient databaseId containerId auxContainerId }
110-
111- /// CosmosSync: When using a ReadOnly connection string, the leases need to be maintained alongside the target
112- member x.ConnectFeedReadOnly ( databaseId , containerId , auxClient , auxDatabaseId , auxContainerId ) = async {
113- let! client = x.CreateAndInitialize( " Main" , databaseId, [| containerId |])
114- let source = CosmosStoreConnector.getSource client databaseId containerId
115- let leases = CosmosStoreConnector.getLeases auxClient auxDatabaseId auxContainerId
116- return source, leases }
117-
118- member x.ConnectContext ( role , databaseId , containerId : string , maxEvents ) = async {
119- let! client = x.Connect( role, databaseId, [| containerId |])
120- return client.CreateContext( role, databaseId, containerId, tipMaxEvents = maxEvents) }
64+ module CosmosStoreConnector =
65+
66+ let private get ( role : string ) ( client : Microsoft.Azure.Cosmos.CosmosClient ) databaseId containerId =
67+ Log.Information( " CosmosDB {role} {database}/{container}" , role, databaseId, containerId)
68+ client.GetDatabase( databaseId) .GetContainer( containerId)
69+ let getSource = get " Source"
70+ let getLeases = get " Leases"
71+ let createMonitoredAndLeases client databaseId containerId auxContainerId =
72+ getSource client databaseId containerId, getLeases client databaseId auxContainerId
73+
74+ type Equinox.CosmosStore.CosmosStoreContext with
75+
76+ member x.LogConfiguration ( role , databaseId : string , containerId : string ) =
77+ Log.Information( " CosmosStore {role:l} {database}/{container} Tip maxEvents {maxEvents} maxSize {maxJsonLen} Query maxItems {queryMaxItems}" ,
78+ role, databaseId, containerId, x.TipOptions.MaxEvents, x.TipOptions.MaxJsonLength, x.QueryOptions.MaxItems)
79+
80+ type Equinox.CosmosStore.CosmosStoreClient with
81+
82+ member x.CreateContext ( role : string , databaseId , containerId , tipMaxEvents , ? queryMaxItems , ? tipMaxJsonLength , ? skipLog ) =
83+ let c = Equinox.CosmosStore.CosmosStoreContext( x, databaseId, containerId, tipMaxEvents, ?queryMaxItems = queryMaxItems, ?tipMaxJsonLength = tipMaxJsonLength)
84+ if skipLog = Some true then () else c.LogConfiguration( role, databaseId, containerId)
85+ c
86+
87+ type Equinox.CosmosStore.CosmosStoreConnector with
88+
89+ member private x.LogConfiguration ( role , databaseId : string , containers : string []) =
90+ let o = x.Options
91+ let timeout , retries429 , timeout429 = o.RequestTimeout, o.MaxRetryAttemptsOnRateLimitedRequests, o.MaxRetryWaitTimeOnRateLimitedRequests
92+ Log.Information( " CosmosDB {role} {mode} {endpointUri} {database}/{containers} timeout {timeout}s Retries {retries}<{maxRetryWaitTime}s" ,
93+ role, o.ConnectionMode, x.Endpoint, databaseId, containers, timeout.TotalSeconds, retries429, let t = timeout429.Value in t.TotalSeconds)
94+ member private x.CreateAndInitialize ( role , databaseId , containers ) =
95+ x.LogConfiguration( role, databaseId, containers)
96+ x.CreateAndInitialize( databaseId, containers)
97+ member private x.Connect ( role , databaseId , containers ) =
98+ x.LogConfiguration( role, databaseId, containers)
99+ x.Connect( databaseId, containers)
100+
101+ // NOTE uses CreateUninitialized as the Database/Container may not actually exist yet
102+ member x.CreateLeasesContainer ( databaseId , auxContainerId ) =
103+ x.LogConfiguration( " Feed" , databaseId, [| auxContainerId |])
104+ let client = x.CreateUninitialized()
105+ CosmosStoreConnector.getLeases client databaseId auxContainerId
106+
107+ member x.ConnectFeed ( databaseId , containerId , auxContainerId ) = async {
108+ let! cosmosClient = x.CreateAndInitialize( " Feed" , databaseId, [| containerId; auxContainerId |])
109+ return CosmosStoreConnector.createMonitoredAndLeases cosmosClient databaseId containerId auxContainerId }
110+
111+ /// CosmosSync: When using a ReadOnly connection string, the leases need to be maintained alongside the target
112+ member x.ConnectFeedReadOnly ( databaseId , containerId , auxClient , auxDatabaseId , auxContainerId ) = async {
113+ let! client = x.CreateAndInitialize( " Main" , databaseId, [| containerId |])
114+ let source = CosmosStoreConnector.getSource client databaseId containerId
115+ let leases = CosmosStoreConnector.getLeases auxClient auxDatabaseId auxContainerId
116+ return source, leases }
117+
118+ member x.ConnectContext ( role , databaseId , containerId : string , maxEvents ) = async {
119+ let! client = x.Connect( role, databaseId, [| containerId |])
120+ return client.CreateContext( role, databaseId, containerId, tipMaxEvents = maxEvents) }
0 commit comments