|
1 |
| -using System; |
| 1 | +using System.Threading; |
2 | 2 | using System.Threading.Tasks;
|
3 | 3 | using Microsoft.Azure.Cosmos;
|
4 |
| -using Microsoft.Extensions.Logging; |
5 | 4 | using WorkflowCore.Providers.Azure.Interface;
|
6 | 5 |
|
7 | 6 | namespace WorkflowCore.Providers.Azure.Services
|
8 | 7 | {
|
9 | 8 | public class CosmosDbProvisioner : ICosmosDbProvisioner
|
10 | 9 | {
|
| 10 | + private readonly ICosmosClientFactory _clientFactory; |
| 11 | + private readonly CosmosDbStorageOptions _cosmosDbStorageOptions; |
11 | 12 |
|
12 |
| - private ICosmosClientFactory _clientFactory; |
13 |
| - |
14 |
| - public CosmosDbProvisioner(ICosmosClientFactory clientFactory, ILoggerFactory loggerFactory) |
| 13 | + public CosmosDbProvisioner( |
| 14 | + ICosmosClientFactory clientFactory, |
| 15 | + CosmosDbStorageOptions cosmosDbStorageOptions) |
15 | 16 | {
|
16 | 17 | _clientFactory = clientFactory;
|
| 18 | + _cosmosDbStorageOptions = cosmosDbStorageOptions; |
17 | 19 | }
|
18 | 20 |
|
19 |
| - public async Task Provision(string dbId) |
| 21 | + public async Task Provision(string dbId, CancellationToken cancellationToken = default) |
20 | 22 | {
|
21 |
| - var dbResp = await _clientFactory.GetCosmosClient().CreateDatabaseIfNotExistsAsync(dbId); |
| 23 | + var dbResp = await _clientFactory.GetCosmosClient().CreateDatabaseIfNotExistsAsync(dbId, cancellationToken: cancellationToken); |
22 | 24 | var wfIndexPolicy = new IndexingPolicy();
|
23 | 25 | wfIndexPolicy.IncludedPaths.Add(new IncludedPath { Path = @"/*" });
|
24 | 26 | wfIndexPolicy.ExcludedPaths.Add(new ExcludedPath { Path = @"/ExecutionPointers/?" });
|
25 | 27 |
|
26 | 28 | Task.WaitAll(
|
27 |
| - dbResp.Database.CreateContainerIfNotExistsAsync(new ContainerProperties(CosmosDbPersistenceProvider.WorkflowContainerName, @"/id") |
| 29 | + dbResp.Database.CreateContainerIfNotExistsAsync(new ContainerProperties(_cosmosDbStorageOptions.WorkflowContainerName, @"/id") |
28 | 30 | {
|
29 | 31 | IndexingPolicy = wfIndexPolicy
|
30 | 32 | }),
|
31 |
| - dbResp.Database.CreateContainerIfNotExistsAsync(new ContainerProperties(CosmosDbPersistenceProvider.EventContainerName, @"/id")), |
32 |
| - dbResp.Database.CreateContainerIfNotExistsAsync(new ContainerProperties(CosmosDbPersistenceProvider.SubscriptionContainerName, @"/id")) |
| 33 | + dbResp.Database.CreateContainerIfNotExistsAsync(new ContainerProperties(_cosmosDbStorageOptions.EventContainerName, @"/id")), |
| 34 | + dbResp.Database.CreateContainerIfNotExistsAsync(new ContainerProperties(_cosmosDbStorageOptions.SubscriptionContainerName, @"/id")) |
33 | 35 | );
|
34 | 36 | }
|
35 | 37 | }
|
|
0 commit comments