-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathSqlOrchestrationServiceSettings.cs
More file actions
204 lines (175 loc) · 8.7 KB
/
SqlOrchestrationServiceSettings.cs
File metadata and controls
204 lines (175 loc) · 8.7 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace DurableTask.SqlServer
{
using System;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json;
/// <summary>
/// Configuration settings for the <see cref="SqlOrchestrationService"/>.
/// </summary>
public class SqlOrchestrationServiceSettings
{
/// <summary>
/// Initializes a new instance of the <see cref="SqlOrchestrationServiceSettings"/> class.
/// </summary>
/// <param name="connectionString">The connection string for connecting to the database.</param>
/// <param name="taskHubName">Optional. The name of the task hub. If not specified, a default name will be used.</param>
/// <param name="schemaName">Optional. The name of the schema. If not specified, the default 'dt' value will be used.</param>
public SqlOrchestrationServiceSettings(string connectionString, string? taskHubName = null, string? schemaName = null)
{
if (string.IsNullOrEmpty(connectionString))
{
throw new ArgumentNullException(nameof(connectionString));
}
this.TaskHubName = taskHubName ?? "default";
this.SchemaName = schemaName ?? "dt";
var builder = new SqlConnectionStringBuilder(connectionString)
{
// We use the task hub name as the application name so that
// stored procedures have easy access to this information.
ApplicationName = this.TaskHubName,
};
if (string.IsNullOrEmpty(builder.InitialCatalog))
{
throw new ArgumentException("Database or Initial Catalog must be specified in the connection string.", nameof(connectionString));
}
this.DatabaseName = builder.InitialCatalog;
this.TaskHubConnectionString = builder.ToString();
}
/// <summary>
/// Gets or sets the number of events that can be dequeued at a time.
/// </summary>
[JsonProperty("workItemBatchSize")]
public int WorkItemBatchSize { get; set; } = 10;
/// <summary>
/// Gets or sets the amount of time a work item is locked after being dequeued.
/// </summary>
[JsonProperty("workItemLockTimeout")]
public TimeSpan WorkItemLockTimeout { get; set; } = TimeSpan.FromMinutes(2);
/// <summary>
/// Gets or sets the name of the task hub.
/// </summary>
[JsonProperty("taskHubName")]
public string TaskHubName { get; }
/// <summary>
/// Gets the name of the schema.
/// </summary>
[JsonProperty("schemaName")]
public string SchemaName { get; }
/// <summary>
/// Gets or sets the name of the app. Used for logging purposes.
/// </summary>
[JsonProperty("appName")]
public string AppName { get; set; } = Environment.MachineName;
/// <summary>
/// Gets or sets the maximum number of work items that can be processed concurrently by a single worker.
/// The default value is the value of <see cref="Environment.ProcessorCount"/>.
/// </summary>
[JsonProperty("maxConcurrentActivities")]
public int MaxConcurrentActivities { get; set; } = Environment.ProcessorCount;
/// <summary>
/// Gets or sets the maximum number of orchestrations that can be loaded in memory at a time by a single worker.
/// The default value is the value of <see cref="Environment.ProcessorCount"/>.
/// </summary>
/// <remarks>
/// Orchestrations that are idle and waiting for inputs are unloaded from memory and do not count against this limit.
/// </remarks>
[JsonProperty("maxActiveOrchestrations")]
public int MaxActiveOrchestrations { get; set; } = Environment.ProcessorCount;
/// <summary>
/// Gets or sets a flag indicating whether to enable extended sessions.
/// </summary>
[JsonProperty("extendedSessionsEnabled")]
public bool ExtendedSessionsEnabled { get; set; } = false;
/// <summary>
/// Gets or sets the number of seconds before an idle session times out.
/// </summary>
[JsonProperty("extendedSessionIdleTimeout")]
public TimeSpan ExtendedSessionIdleTimeout { get; set; } = TimeSpan.FromSeconds(30);
/// <summary>
/// Gets or sets the minimum interval to poll for orchestrations.
/// Polling interval increases when no orchestrations or activities are found.
/// The default value is 50 milliseconds.
/// </summary>
[JsonProperty("minOrchestrationPollingInterval")]
public TimeSpan MinOrchestrationPollingInterval { get; set; } = TimeSpan.FromMilliseconds(50);
/// <summary>
/// Gets or sets the maximum interval to poll for orchestrations.
/// Polling interval increases when no orchestrations or activities are found.
/// The default value is 3 seconds.
/// </summary>
[JsonProperty("maxOrchestrationPollingInterval")]
public TimeSpan MaxOrchestrationPollingInterval { get; set; } = TimeSpan.FromSeconds(3);
/// <summary>
/// Gets or sets the delta backoff interval to poll for orchestrations.
/// Polling interval increases by this delta when no orchestrations are found.
/// The default value is 50 milliseconds.
/// </summary>
[JsonProperty("deltaBackoffOrchestrationPollingInterval")]
public TimeSpan DeltaBackoffOrchestrationPollingInterval { get; set; } = TimeSpan.FromMilliseconds(50);
/// <summary>
/// Gets or sets the minimum interval to poll for activities.
/// Polling interval increases when no activities are found.
/// The default value is 50 milliseconds.
/// </summary>
[JsonProperty("minActivityPollingInterval")]
public TimeSpan MinActivityPollingInterval { get; set; } = TimeSpan.FromMilliseconds(50);
/// <summary>
/// Gets or sets the maximum interval to poll for activities.
/// Polling interval increases when no activities are found.
/// The default value is 3 seconds.
/// </summary>
[JsonProperty("maxActivityPollingInterval")]
public TimeSpan MaxActivityPollingInterval { get; set; } = TimeSpan.FromSeconds(3);
/// <summary>
/// Gets or sets the delta backoff interval to poll for activities.
/// Polling interval increases by this delta when no activities are found.
/// The default value is 50 milliseconds.
/// </summary>
[JsonProperty("deltaBackoffActivityPollingInterval")]
public TimeSpan DeltaBackoffActivityPollingInterval { get; set; } = TimeSpan.FromMilliseconds(50);
/// <summary>
/// Gets or sets a flag indicating whether the database should be automatically created if it does not exist.
/// </summary>
/// <remarks>
/// If <see langword="true"/>, the user requires the permission <c>CREATE DATABASE</c>.
/// </remarks>
[JsonProperty("createDatabaseIfNotExists")]
public bool CreateDatabaseIfNotExists { get; set; }
/// <summary>
/// Gets a SQL connection string associated with the configured task hub.
/// </summary>
[JsonIgnore]
public string TaskHubConnectionString { get; }
/// <summary>
/// Gets a <see cref="ILoggerFactory"/> used for writing logs to the DurableTask.SqlServer trace source.
/// </summary>
[JsonIgnore]
public ILoggerFactory LoggerFactory { get; set; } = NullLoggerFactory.Instance;
/// <summary>
/// Gets or sets the name of the database that contains the instance store.
/// </summary>
/// <remarks>
/// This value is derived from the value of the <c>"Initial Catalog"</c> or <c>"Database"</c>
/// attribute in the <see cref="TaskHubConnectionString"/>.
/// </remarks>
[JsonIgnore]
public string DatabaseName { get; set; }
internal SqlConnection CreateConnection() => new SqlConnection(this.TaskHubConnectionString);
internal SqlConnection CreateConnection(string databaseName)
{
if (databaseName == this.DatabaseName)
{
return this.CreateConnection();
}
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(this.TaskHubConnectionString)
{
InitialCatalog = databaseName
};
return new SqlConnection(builder.ToString());
}
}
}