Skip to content

Commit 15c0b10

Browse files
committed
Add husky and apply some code fixes
1 parent dac90d4 commit 15c0b10

File tree

224 files changed

+9415
-9671
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+9415
-9671
lines changed

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"husky": {
6+
"version": "0.5.4",
7+
"commands": [
8+
"husky"
9+
]
10+
}
11+
}
12+
}

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ indent_size = 2
3939
[*.{cs,vb}]
4040

4141
# IDE0055: Fix formatting
42+
csharp_style_namespace_declarations = file_scoped:warning
4243
dotnet_diagnostic.IDE0055.severity = warning
44+
dotnet_diagnostic.IDE0005.severity = warning # remove unecessary usings
45+
dotnet_diagnostic.IDE0007.severity = warning # use var instead of explicit type
46+
dotnet_diagnostic.IDE0044.severity = warning # make field readonly
47+
dotnet_diagnostic.IDE0059.severity = warning # unecessary assignment
48+
dotnet_diagnostic.IDE0063.severity = warning # using statement can be simplified
49+
dotnet_diagnostic.IDE0090.severity = warning # new expression can be simplified
50+
dotnet_diagnostic.CA1825.severity = warning # avoid unecessary zero array allocation
4351

4452
# Sort using and Import directives with System.* appearing first
4553
dotnet_sort_system_directives_first = true

.husky/pre-commit

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
## husky task runner examples -------------------
5+
## Note : for local installation use 'dotnet' prefix. e.g. 'dotnet husky'
6+
7+
## run all tasks
8+
#husky run
9+
10+
### run all tasks with group: 'group-name'
11+
#husky run --group group-name
12+
13+
## run task with name: 'task-name'
14+
#husky run --name task-name
15+
16+
## pass hook arguments to task
17+
#husky run --args "$1" "$2"
18+
19+
## or put your custom commands -------------------
20+
#echo 'Husky.Net is awesome!'
21+
22+
echo 'Husky.Net is awesome!'

.husky/task-runner.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"tasks": [
3+
{
4+
"name": "Run dotnet format",
5+
"command": "dotnet",
6+
"args": [
7+
"dotnet",
8+
"format",
9+
"--severity",
10+
"warn",
11+
"--include",
12+
"${staged}"
13+
],
14+
"include": ["**/*.cs"]
15+
}
16+
]
17+
}
18+

benchmark/StoragesBenchmark/AzureStorageBenchmark.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@
22
using Microsoft.Extensions.Configuration;
33
using Microsoft.Extensions.DependencyInjection;
44

5-
namespace StoragesBenchmark
5+
namespace StoragesBenchmark;
6+
7+
public class AzureStorageBenchmark : OrchestrationBenchmark
68
{
7-
public class AzureStorageBenchmark : OrchestrationBenchmark
9+
protected override void ConfigureStorage(IServiceCollection services)
810
{
9-
protected override void ConfigureStorage(IServiceCollection services)
10-
{
11-
var connectionString = _configuration.GetConnectionString("AzureStorageAccount");
12-
13-
services.AddDurableTaskAzureStorage(options =>
14-
{
15-
options.TaskHubName = "test";
16-
options.StorageConnectionString = connectionString;
17-
});
18-
}
11+
var connectionString = _configuration.GetConnectionString("AzureStorageAccount");
1912

20-
protected override void ConfigureWorker(IDurableTaskWorkerBuilder builder)
13+
services.AddDurableTaskAzureStorage(options =>
2114
{
22-
base.ConfigureWorker(builder);
23-
builder.HasAllOrchestrations = true;
24-
builder.HasAllActivities = true;
25-
}
15+
options.TaskHubName = "test";
16+
options.StorageConnectionString = connectionString;
17+
});
18+
}
19+
20+
protected override void ConfigureWorker(IDurableTaskWorkerBuilder builder)
21+
{
22+
base.ConfigureWorker(builder);
23+
builder.HasAllOrchestrations = true;
24+
builder.HasAllActivities = true;
2625
}
2726
}

benchmark/StoragesBenchmark/DurableTaskSqlServerBenchmark.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,28 @@
44
using Microsoft.Extensions.Configuration;
55
using Microsoft.Extensions.DependencyInjection;
66

7-
namespace StoragesBenchmark
7+
namespace StoragesBenchmark;
8+
9+
public class DurableTaskSqlServerBenchmark : OrchestrationBenchmark
810
{
9-
public class DurableTaskSqlServerBenchmark : OrchestrationBenchmark
11+
protected override void ConfigureStorage(IServiceCollection services)
1012
{
11-
protected override void ConfigureStorage(IServiceCollection services)
12-
{
13-
var connectionString = _configuration.GetConnectionString("SqlServer");
13+
var connectionString = _configuration.GetConnectionString("SqlServer");
1414

15-
var settings = new SqlOrchestrationServiceSettings(connectionString);
15+
var settings = new SqlOrchestrationServiceSettings(connectionString);
1616

17-
var provider = new SqlOrchestrationService(settings);
18-
provider.CreateIfNotExistsAsync().GetAwaiter().GetResult();
17+
var provider = new SqlOrchestrationService(settings);
18+
provider.CreateIfNotExistsAsync().GetAwaiter().GetResult();
1919

20-
services.AddSingleton<SqlOrchestrationService>(provider);
21-
services.AddSingleton<IOrchestrationService>(p => p.GetRequiredService<SqlOrchestrationService>());
22-
services.AddSingleton<IOrchestrationServiceClient>(p => p.GetRequiredService<SqlOrchestrationService>());
23-
}
20+
services.AddSingleton<SqlOrchestrationService>(provider);
21+
services.AddSingleton<IOrchestrationService>(p => p.GetRequiredService<SqlOrchestrationService>());
22+
services.AddSingleton<IOrchestrationServiceClient>(p => p.GetRequiredService<SqlOrchestrationService>());
23+
}
2424

25-
protected override void ConfigureWorker(IDurableTaskWorkerBuilder builder)
26-
{
27-
base.ConfigureWorker(builder);
28-
builder.HasAllOrchestrations = true;
29-
builder.HasAllActivities = true;
30-
}
25+
protected override void ConfigureWorker(IDurableTaskWorkerBuilder builder)
26+
{
27+
base.ConfigureWorker(builder);
28+
builder.HasAllOrchestrations = true;
29+
builder.HasAllActivities = true;
3130
}
3231
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
using System;
22
using Microsoft.Extensions.DependencyInjection;
33

4-
namespace StoragesBenchmark
4+
namespace StoragesBenchmark;
5+
6+
public class InMemoryEFCoreBenchmark : OrchestrationBenchmark
57
{
6-
public class InMemoryEFCoreBenchmark : OrchestrationBenchmark
8+
protected override void ConfigureStorage(IServiceCollection services)
79
{
8-
protected override void ConfigureStorage(IServiceCollection services)
9-
{
10-
services.AddDurableTaskEFCoreStorage()
11-
.UseInMemoryDatabase(Guid.NewGuid().ToString());
12-
}
10+
services.AddDurableTaskEFCoreStorage()
11+
.UseInMemoryDatabase(Guid.NewGuid().ToString());
1312
}
1413
}

benchmark/StoragesBenchmark/MySqlEFCoreBenchmark.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
using Microsoft.Extensions.Configuration;
33
using Microsoft.Extensions.DependencyInjection;
44

5-
namespace StoragesBenchmark
5+
namespace StoragesBenchmark;
6+
7+
public class MySqlEFCoreBenchmark : OrchestrationBenchmark
68
{
7-
public class MySqlEFCoreBenchmark : OrchestrationBenchmark
9+
protected override void ConfigureStorage(IServiceCollection services)
810
{
9-
protected override void ConfigureStorage(IServiceCollection services)
10-
{
11-
var connectionString = _configuration.GetConnectionString("MySql");
11+
var connectionString = _configuration.GetConnectionString("MySql");
1212

13-
services.AddDurableTaskEFCoreStorage()
14-
.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
15-
}
13+
services.AddDurableTaskEFCoreStorage()
14+
.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
1615
}
1716
}

benchmark/StoragesBenchmark/OrchestrationBenchmark.cs

Lines changed: 67 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -12,93 +12,92 @@
1212
using Microsoft.Extensions.Hosting;
1313
using IHost = Microsoft.Extensions.Hosting.IHost;
1414

15-
namespace StoragesBenchmark
15+
namespace StoragesBenchmark;
16+
17+
[SimpleJob(RunStrategy.Monitoring, iterationCount: 5)]
18+
19+
public abstract class OrchestrationBenchmark
1620
{
17-
[SimpleJob(RunStrategy.Monitoring, iterationCount: 5)]
21+
[Params(100)]
22+
public int NumberOfOrchestrations;
1823

19-
public abstract class OrchestrationBenchmark
20-
{
21-
[Params(100)]
22-
public int NumberOfOrchestrations;
24+
[Params(5)]
25+
public int NumberOfActivities;
2326

24-
[Params(5)]
25-
public int NumberOfActivities;
27+
protected IHost _host;
28+
protected IConfiguration _configuration;
2629

27-
protected IHost _host;
28-
protected IConfiguration _configuration;
30+
[GlobalSetup]
31+
public async Task Setup()
32+
{
33+
_configuration = new ConfigurationBuilder()
34+
.AddJsonFile("appsettings.json", false)
35+
.AddJsonFile("appsettings.private.json", true)
36+
.AddEnvironmentVariables()
37+
.Build();
38+
39+
_host = await Host.CreateDefaultBuilder()
40+
.ConfigureServices(services =>
41+
{
42+
ConfigureStorage(services);
2943

30-
[GlobalSetup]
31-
public async Task Setup()
32-
{
33-
_configuration = new ConfigurationBuilder()
34-
.AddJsonFile("appsettings.json", false)
35-
.AddJsonFile("appsettings.private.json", true)
36-
.AddEnvironmentVariables()
37-
.Build();
38-
39-
_host = await Host.CreateDefaultBuilder()
40-
.ConfigureServices(services =>
44+
services.AddDurableTaskClient();
45+
46+
services.AddDurableTaskWorker(builder =>
4147
{
42-
ConfigureStorage(services);
48+
ConfigureWorker(builder);
49+
});
50+
}).StartAsync();
51+
}
4352

44-
services.AddDurableTaskClient();
53+
[GlobalCleanup]
54+
public async Task Cleanup()
55+
{
56+
await _host.StopAsync();
57+
_host.Dispose();
58+
}
4559

46-
services.AddDurableTaskWorker(builder =>
47-
{
48-
ConfigureWorker(builder);
49-
});
50-
}).StartAsync();
51-
}
60+
protected abstract void ConfigureStorage(IServiceCollection services);
5261

53-
[GlobalCleanup]
54-
public async Task Cleanup()
55-
{
56-
await _host.StopAsync();
57-
_host.Dispose();
58-
}
62+
protected virtual void ConfigureWorker(IDurableTaskWorkerBuilder builder)
63+
{
64+
builder.AddAnnotatedFrom(typeof(Orchestrations));
65+
}
66+
67+
[Benchmark]
68+
public async Task RunOrchestrations()
69+
{
70+
var taskHubClient = _host.Services.GetRequiredService<TaskHubClient>();
5971

60-
protected abstract void ConfigureStorage(IServiceCollection services);
72+
var instances = new List<OrchestrationInstance>();
6173

62-
protected virtual void ConfigureWorker(IDurableTaskWorkerBuilder builder)
74+
for (var i = 0; i < NumberOfOrchestrations; i++)
6375
{
64-
builder.AddAnnotatedFrom(typeof(Orchestrations));
76+
var instance = await taskHubClient.CreateOrchestrationInstanceAsync("RunActivities", "", NumberOfActivities);
77+
instances.Add(instance);
6578
}
6679

67-
[Benchmark]
68-
public async Task RunOrchestrations()
80+
foreach (var instance in instances)
6981
{
70-
var taskHubClient = _host.Services.GetRequiredService<TaskHubClient>();
71-
72-
var instances = new List<OrchestrationInstance>();
73-
74-
for (var i = 0; i < NumberOfOrchestrations; i++)
75-
{
76-
var instance = await taskHubClient.CreateOrchestrationInstanceAsync("RunActivities", "", NumberOfActivities);
77-
instances.Add(instance);
78-
}
79-
80-
foreach (var instance in instances)
81-
{
82-
var state = await taskHubClient.WaitForOrchestrationAsync(instance, TimeSpan.FromMinutes(30));
83-
if (state == null || state.OrchestrationStatus != OrchestrationStatus.Completed)
84-
throw new Exception("Orchestration did not complete");
85-
}
82+
var state = await taskHubClient.WaitForOrchestrationAsync(instance, TimeSpan.FromMinutes(30));
83+
if (state == null || state.OrchestrationStatus != OrchestrationStatus.Completed)
84+
throw new Exception("Orchestration did not complete");
8685
}
86+
}
8787

88-
public class Orchestrations
88+
public class Orchestrations
89+
{
90+
[Orchestration(Name = "RunActivities")]
91+
public async Task Run(OrchestrationContext context, int numberOfActivities)
8992
{
90-
[Orchestration(Name = "RunActivities")]
91-
public async Task Run(OrchestrationContext context, int numberOfActivities)
92-
{
93-
var tasks = Enumerable.Range(0, numberOfActivities).Select(e => context.ScheduleTask<Guid>("EmptyActivity", ""));
94-
await Task.WhenAll(tasks);
95-
}
93+
var tasks = Enumerable.Range(0, numberOfActivities).Select(e => context.ScheduleTask<Guid>("EmptyActivity", ""));
94+
await Task.WhenAll(tasks);
95+
}
9696

97-
[Activity(Name = "EmptyActivity")]
98-
public Guid EmptyActivity()
99-
{
100-
return Guid.NewGuid();
101-
}
97+
[Activity(Name = "EmptyActivity")]
98+
public Guid EmptyActivity()
99+
{
100+
return Guid.NewGuid();
102101
}
103102
}
104103
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using Microsoft.Extensions.Configuration;
22
using Microsoft.Extensions.DependencyInjection;
33

4-
namespace StoragesBenchmark
4+
namespace StoragesBenchmark;
5+
6+
public class PostgresEFCoreBenchmark : OrchestrationBenchmark
57
{
6-
public class PostgresEFCoreBenchmark : OrchestrationBenchmark
8+
protected override void ConfigureStorage(IServiceCollection services)
79
{
8-
protected override void ConfigureStorage(IServiceCollection services)
9-
{
10-
var connectionString = _configuration.GetConnectionString("Postgres");
10+
var connectionString = _configuration.GetConnectionString("Postgres");
1111

12-
services.AddDurableTaskEFCoreStorage()
13-
.UseNpgsql(connectionString);
14-
}
12+
services.AddDurableTaskEFCoreStorage()
13+
.UseNpgsql(connectionString);
1514
}
1615
}

0 commit comments

Comments
 (0)