-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDurableTaskSqlServerBenchmark.cs
More file actions
48 lines (38 loc) · 1.78 KB
/
DurableTaskSqlServerBenchmark.cs
File metadata and controls
48 lines (38 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using DurableTask.Core;
using DurableTask.SqlServer;
using LLL.DurableTask.Worker.Builder;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace StoragesBenchmark;
public class DurableTaskSqlServerBenchmark : OrchestrationBenchmark
{
protected override void ConfigureStorage(IServiceCollection services)
{
var connectionString = _configuration.GetConnectionString("SqlServer");
EnsureDatabaseExists(connectionString);
var settings = new SqlOrchestrationServiceSettings(connectionString);
var provider = new SqlOrchestrationService(settings);
provider.CreateIfNotExistsAsync().GetAwaiter().GetResult();
services.AddSingleton<SqlOrchestrationService>(provider);
services.AddSingleton<IOrchestrationService>(p => p.GetRequiredService<SqlOrchestrationService>());
services.AddSingleton<IOrchestrationServiceClient>(p => p.GetRequiredService<SqlOrchestrationService>());
}
protected override void ConfigureWorker(IDurableTaskWorkerBuilder builder)
{
base.ConfigureWorker(builder);
builder.HasAllOrchestrations = true;
builder.HasAllActivities = true;
}
private static void EnsureDatabaseExists(string connectionString)
{
var builder = new SqlConnectionStringBuilder(connectionString);
var database = builder.InitialCatalog;
builder.InitialCatalog = "master";
using var connection = new SqlConnection(builder.ConnectionString);
connection.Open();
using var command = connection.CreateCommand();
command.CommandText = $"IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '{database}') CREATE DATABASE [{database}]";
command.ExecuteNonQuery();
}
}