-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathDurableTaskWorkerOptions.cs
More file actions
233 lines (209 loc) · 9.81 KB
/
DurableTaskWorkerOptions.cs
File metadata and controls
233 lines (209 loc) · 9.81 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.DurableTask.Converters;
namespace Microsoft.DurableTask.Worker;
/// <summary>
/// Options for the Durable Task worker.
/// </summary>
public class DurableTaskWorkerOptions
{
DataConverter dataConverter = JsonDataConverter.Default;
/// <summary>
/// Defines the version matching strategy for the Durable Task worker.
/// </summary>
public enum VersionMatchStrategy
{
/// <summary>
/// Ignore Orchestration version, all work received is processed.
/// </summary>
None = 0,
/// <summary>
/// Worker will only process Tasks from Orchestrations with the same version as the worker.
/// </summary>
Strict = 1,
/// <summary>
/// Worker will process Tasks from Orchestrations whose version is less than or equal to the worker.
/// </summary>
CurrentOrOlder = 2,
}
/// <summary>
/// Defines the versioning failure strategy for the Durable Task worker.
/// </summary>
public enum VersionFailureStrategy
{
/// <summary>
/// Do not change the orchestration state if the version does not adhere to the matching strategy.
/// </summary>
Reject = 0,
/// <summary>
/// Fail the orchestration if the version does not adhere to the matching strategy.
/// </summary>
Fail = 1,
}
/// <summary>
/// Gets or sets the data converter. Default value is <see cref="JsonDataConverter.Default" />.
/// </summary>
/// <remarks>
/// <para>
/// This is used for serializing inputs and outputs of <see cref="ITaskOrchestrator" /> and
/// <see cref="ITaskActivity" />.
/// </para><para>
/// When set to <c>null</c>, this will revert to <see cref="JsonDataConverter.Default" />.
/// </para><para>
/// WARNING: When changing this value, ensure backwards compatibility is preserved for any in-flight
/// orchestrations. If it is not, deserialization - and the orchestration - may fail.
/// </para>
/// </remarks>
public DataConverter DataConverter
{
get => this.dataConverter;
set
{
if (value is null)
{
this.dataConverter = JsonDataConverter.Default;
this.DataConverterExplicitlySet = false;
}
else
{
this.dataConverter = value;
this.DataConverterExplicitlySet = true;
}
}
}
/// <summary>
/// Gets or sets a value indicating whether this client should support entities. If true, all instance ids starting
/// with '@' are reserved for entities, and validation checks are performed where appropriate.
/// </summary>
public bool EnableEntitySupport { get; set; }
/// <summary>
/// Gets or sets the maximum timer interval for the
/// <see cref="TaskOrchestrationContext.CreateTimer(TimeSpan, CancellationToken)"/> method.
/// </summary>
/// <remarks>
/// <para>
/// The default maximum timer interval is 3 days. If a
/// <see cref="TaskOrchestrationContext.CreateTimer(TimeSpan, CancellationToken)"/> call
/// specifies a 7-day timer, it will be implemented using three separate timers: two for 3 days and one for 1 day.
/// </para><para>
/// Long timers are broken up into smaller timers to support certain types of backend storage providers which have
/// limits on how long a durable timer entity can be created. For example, the Azure Storage state provider uses
/// scheduled queue messages to implement durable timers, but scheduled queue messages cannot exceed 7 days. In
/// order to support longer durable timers, a long timer is broken up into smaller timers internally. This division
/// into multiple timers is not visible to user code. However, it is visible in the generated orchestration
/// history.
/// </para><para>
/// Be aware that changing this setting may be breaking for in-flight orchestrations. For example, if an existing
/// orchestration has created a timer that exceeds the maximum interval (e.g., a 7 day timer), and this value is
/// subsequently changed to a higher value (e.g., from 3 days to 10 days) then the next reply of the existing
/// orchestration will fail with a non-determinism error because the number of intermediate timers scheduled during
/// the replay (e.g., one timer) will no longer match the number of timers that exist in the orchestration history
/// (e.g., two timers).
/// </para><para>
/// To avoid accidentally breaking existing orchestrations, this value should only be changed for new applications
/// with no state or when an application is known to have no in-flight orchestration instances.
/// </para><para>
/// WARNING: Changing this value from a previously configured value is a breaking change for in-flight
/// orchestrations.
/// </para>
/// </remarks>
public TimeSpan MaximumTimerInterval { get; set; } = TimeSpan.FromDays(3);
/// <summary>
/// Gets options for the Durable Task worker concurrency.
/// </summary>
/// <remarks>
/// Worker concurrency options control how many work items of a particular type (e.g., orchestration, activity,
/// or entity) can be processed concurrently by the worker. It is recommended to set these values based on the
/// expected workload and the resources available on the machine running the worker.
/// </remarks>
public ConcurrencyOptions Concurrency { get; } = new();
/// <summary>
/// Gets or sets the versioning options for the Durable Task worker.
/// </summary>
/// <remarks>
/// Worker versioning controls how a worker will handle orchestrations of different versions. Defining both the
/// version of the worker, the versions that can be worked on, and what to do in case a version does not comply
/// with the given options.
/// </remarks>
public VersioningOptions? Versioning { get; set; }
/// <summary>
/// Gets a value indicating whether versioning is explicitly set or not.
/// </summary>
public bool IsVersioningSet { get; internal set; }
/// <summary>
/// Gets or sets a callback function that determines whether an orchestration should be accepted for work.
/// </summary>
[Obsolete("Experimental")]
public IOrchestrationFilter? OrchestrationFilter { get; set; }
/// <summary>
/// Gets a value indicating whether <see cref="DataConverter" /> was explicitly set or not.
/// </summary>
/// <remarks>
/// This value is used to determine if we should resolve <see cref="DataConverter" /> from the
/// <see cref="IServiceProvider" /> or not. If it is explicitly set (even to the default), we
/// will <b>not</b> resolve it. If not set, we will attempt to resolve it. This is so the
/// behavior is consistently irrespective of option configuration ordering.
/// </remarks>
internal bool DataConverterExplicitlySet { get; private set; }
/// <summary>
/// Applies these option values to another.
/// </summary>
/// <param name="other">The other options object to apply to.</param>
internal void ApplyTo(DurableTaskWorkerOptions other)
{
if (other is not null)
{
// Make sure to keep this up to date as values are added.
other.DataConverter = this.DataConverter;
other.MaximumTimerInterval = this.MaximumTimerInterval;
other.EnableEntitySupport = this.EnableEntitySupport;
other.Versioning = this.Versioning;
#pragma warning disable CS0618 // Type or member is obsolete
other.OrchestrationFilter = this.OrchestrationFilter;
#pragma warning restore CS0618 // Type or member is obsolete
}
}
/// <summary>
/// Options for the Durable Task worker concurrency.
/// </summary>
public class ConcurrencyOptions
{
/// <summary>
/// Gets or sets the maximum number of concurrent activity work items that can be processed by the worker.
/// </summary>
public int MaximumConcurrentActivityWorkItems { get; set; } = 100 * Environment.ProcessorCount;
/// <summary>
/// Gets or sets the maximum number of concurrent orchestration work items that can be processed by the worker.
/// </summary>
public int MaximumConcurrentOrchestrationWorkItems { get; set; } = 100 * Environment.ProcessorCount;
/// <summary>
/// Gets or sets the maximum number of concurrent entity work items that can be processed by the worker.
/// </summary>
public int MaximumConcurrentEntityWorkItems { get; set; } = 100 * Environment.ProcessorCount;
}
/// <summary>
/// Options for the Durable Task worker versioning.
/// </summary>
public class VersioningOptions
{
/// <summary>
/// Gets or sets the version of orchestrations that the worker can work on.
/// </summary>
public string Version { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the default version that will be used for starting new orchestrations.
/// </summary>
public string DefaultVersion { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the versioning strategy for the Durable Task worker.
/// </summary>
public VersionMatchStrategy MatchStrategy { get; set; } = VersionMatchStrategy.None;
/// <summary>
/// Gets or sets the versioning failure strategy for the Durable Task worker.
/// </summary>
/// <remarks>
/// If the version matching strategy is set to <see cref="VersionMatchStrategy.None"/>, this value has no effect.
/// </remarks>
public VersionFailureStrategy FailureStrategy { get; set; } = VersionFailureStrategy.Reject;
}
}