@@ -10,7 +10,9 @@ namespace Microsoft.DurableTask.Worker;
10
10
/// </summary>
11
11
public class DurableTaskWorkerOptions
12
12
{
13
- DataConverter dataConverter = JsonDataConverter . Default ;
13
+ DataConverter ? dataConverter ;
14
+ bool ? enableEntitySupport ;
15
+ TimeSpan ? maximumTimerInterval ;
14
16
15
17
/// <summary>
16
18
/// Gets or sets the data converter. Default value is <see cref="JsonDataConverter.Default" />.
@@ -28,27 +30,19 @@ public class DurableTaskWorkerOptions
28
30
/// </remarks>
29
31
public DataConverter DataConverter
30
32
{
31
- get => this . dataConverter ;
32
- set
33
- {
34
- if ( value is null )
35
- {
36
- this . dataConverter = JsonDataConverter . Default ;
37
- this . DataConverterExplicitlySet = false ;
38
- }
39
- else
40
- {
41
- this . dataConverter = value ;
42
- this . DataConverterExplicitlySet = true ;
43
- }
44
- }
33
+ get => this . dataConverter ?? JsonDataConverter . Default ;
34
+ set => this . dataConverter = value ;
45
35
}
46
36
47
37
/// <summary>
48
38
/// Gets or sets a value indicating whether this client should support entities. If true, all instance ids starting
49
39
/// with '@' are reserved for entities, and validation checks are performed where appropriate.
50
40
/// </summary>
51
- public bool EnableEntitySupport { get ; set ; }
41
+ public bool EnableEntitySupport
42
+ {
43
+ get => this . enableEntitySupport ?? false ;
44
+ set => this . enableEntitySupport = value ;
45
+ }
52
46
53
47
/// <summary>
54
48
/// Gets or sets the maximum timer interval for the
@@ -81,7 +75,11 @@ public DataConverter DataConverter
81
75
/// orchestrations.
82
76
/// </para>
83
77
/// </remarks>
84
- public TimeSpan MaximumTimerInterval { get ; set ; } = TimeSpan . FromDays ( 3 ) ;
78
+ public TimeSpan MaximumTimerInterval
79
+ {
80
+ get => this . maximumTimerInterval ?? TimeSpan . FromDays ( 3 ) ;
81
+ set => this . maximumTimerInterval = value ;
82
+ }
85
83
86
84
/// <summary>
87
85
/// Gets options for the Durable Task worker concurrency.
@@ -102,7 +100,7 @@ public DataConverter DataConverter
102
100
/// will <b>not</b> resolve it. If not set, we will attempt to resolve it. This is so the
103
101
/// behavior is consistently irrespective of option configuration ordering.
104
102
/// </remarks>
105
- internal bool DataConverterExplicitlySet { get ; private set ; }
103
+ internal bool DataConverterExplicitlySet => this . dataConverter is not null ;
106
104
107
105
/// <summary>
108
106
/// Applies these option values to another.
@@ -113,9 +111,18 @@ internal void ApplyTo(DurableTaskWorkerOptions other)
113
111
if ( other is not null )
114
112
{
115
113
// Make sure to keep this up to date as values are added.
116
- other . DataConverter = this . DataConverter ;
117
- other . MaximumTimerInterval = this . MaximumTimerInterval ;
118
- other . EnableEntitySupport = this . EnableEntitySupport ;
114
+ ApplyIfSet ( this . dataConverter , ref other . dataConverter ) ;
115
+ ApplyIfSet ( this . enableEntitySupport , ref other . enableEntitySupport ) ;
116
+ ApplyIfSet ( this . maximumTimerInterval , ref other . maximumTimerInterval ) ;
117
+ this . Concurrency . ApplyTo ( other . Concurrency ) ;
118
+ }
119
+ }
120
+
121
+ static void ApplyIfSet < T > ( T ? value , ref T ? target )
122
+ {
123
+ if ( value is not null && target is null )
124
+ {
125
+ target = value ;
119
126
}
120
127
}
121
128
@@ -124,19 +131,51 @@ internal void ApplyTo(DurableTaskWorkerOptions other)
124
131
/// </summary>
125
132
public class ConcurrencyOptions
126
133
{
134
+ static readonly int DefaultMaxConcurrency = 100 * Environment . ProcessorCount ;
135
+
136
+ int ? maxActivity ;
137
+ int ? maxOrchestration ;
138
+ int ? maxEntity ;
139
+
127
140
/// <summary>
128
141
/// Gets or sets the maximum number of concurrent activity work items that can be processed by the worker.
129
142
/// </summary>
130
- public int MaximumConcurrentActivityWorkItems { get ; set ; } = 100 * Environment . ProcessorCount ;
143
+ public int MaximumConcurrentActivityWorkItems
144
+ {
145
+ get => this . maxActivity ?? DefaultMaxConcurrency ;
146
+ set => this . maxActivity = value ;
147
+ }
131
148
132
149
/// <summary>
133
150
/// Gets or sets the maximum number of concurrent orchestration work items that can be processed by the worker.
134
151
/// </summary>
135
- public int MaximumConcurrentOrchestrationWorkItems { get ; set ; } = 100 * Environment . ProcessorCount ;
152
+ public int MaximumConcurrentOrchestrationWorkItems
153
+ {
154
+ get => this . maxOrchestration ?? DefaultMaxConcurrency ;
155
+ set => this . maxOrchestration = value ;
156
+ }
136
157
137
158
/// <summary>
138
159
/// Gets or sets the maximum number of concurrent entity work items that can be processed by the worker.
139
160
/// </summary>
140
- public int MaximumConcurrentEntityWorkItems { get ; set ; } = 100 * Environment . ProcessorCount ;
161
+ public int MaximumConcurrentEntityWorkItems
162
+ {
163
+ get => this . maxEntity ?? DefaultMaxConcurrency ;
164
+ set => this . maxEntity = value ;
165
+ }
166
+
167
+ /// <summary>
168
+ /// Applies these option values to another.
169
+ /// </summary>
170
+ /// <param name="other">The options to apply this options values to.</param>
171
+ internal void ApplyTo ( ConcurrencyOptions other )
172
+ {
173
+ if ( other is not null )
174
+ {
175
+ ApplyIfSet ( this . maxActivity , ref other . maxActivity ) ;
176
+ ApplyIfSet ( this . maxOrchestration , ref other . maxOrchestration ) ;
177
+ ApplyIfSet ( this . maxEntity , ref other . maxEntity ) ;
178
+ }
179
+ }
141
180
}
142
181
}
0 commit comments