Skip to content

Commit 209bed4

Browse files
committed
Fix DurableTaskWorkerOptions.ApplyTo
1 parent 8923128 commit 209bed4

File tree

2 files changed

+81
-62
lines changed

2 files changed

+81
-62
lines changed

src/Client/Core/DurableTaskClientOptions.cs

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace Microsoft.DurableTask.Client;
1010
/// </summary>
1111
public class DurableTaskClientOptions
1212
{
13-
DataConverter dataConverter = JsonDataConverter.Default;
14-
bool enableEntitySupport;
13+
DataConverter? dataConverter;
14+
bool? enableEntitySupport;
1515

1616
/// <summary>
1717
/// Gets or sets the data converter. Default value is <see cref="JsonDataConverter.Default" />.
@@ -31,34 +31,18 @@ public class DurableTaskClientOptions
3131
/// </remarks>
3232
public DataConverter DataConverter
3333
{
34-
get => this.dataConverter;
35-
set
36-
{
37-
if (value is null)
38-
{
39-
this.dataConverter = JsonDataConverter.Default;
40-
this.DataConverterExplicitlySet = false;
41-
}
42-
else
43-
{
44-
this.dataConverter = value;
45-
this.DataConverterExplicitlySet = true;
46-
}
47-
}
34+
get => this.dataConverter ?? JsonDataConverter.Default;
35+
set => this.dataConverter = value;
4836
}
4937

5038
/// <summary>
51-
/// Gets or sets a value indicating whether this client should support entities. If true, all instance ids starting with '@' are reserved for entities,
52-
/// and validation checks are performed where appropriate.
39+
/// Gets or sets a value indicating whether this client should support entities. If true, all instance ids starting
40+
/// with '@' are reserved for entities, and validation checks are performed where appropriate.
5341
/// </summary>
5442
public bool EnableEntitySupport
5543
{
56-
get => this.enableEntitySupport;
57-
set
58-
{
59-
this.enableEntitySupport = value;
60-
this.EntitySupportExplicitlySet = true;
61-
}
44+
get => this.enableEntitySupport ?? false;
45+
set => this.enableEntitySupport = value;
6246
}
6347

6448
/// <summary>
@@ -70,12 +54,7 @@ public bool EnableEntitySupport
7054
/// will <b>not</b> resolve it. If not set, we will attempt to resolve it. This is so the
7155
/// behavior is consistently irrespective of option configuration ordering.
7256
/// </remarks>
73-
internal bool DataConverterExplicitlySet { get; private set; }
74-
75-
/// <summary>
76-
/// Gets a value indicating whether <see cref="EnableEntitySupport" /> was explicitly set or not.
77-
/// </summary>
78-
internal bool EntitySupportExplicitlySet { get; private set; }
57+
internal bool DataConverterExplicitlySet => this.dataConverter is not null;
7958

8059
/// <summary>
8160
/// Applies these option values to another.
@@ -86,15 +65,16 @@ internal void ApplyTo(DurableTaskClientOptions other)
8665
if (other is not null)
8766
{
8867
// Make sure to keep this up to date as values are added.
89-
if (!other.DataConverterExplicitlySet)
90-
{
91-
other.DataConverter = this.DataConverter;
92-
}
68+
ApplyIfSet(this.dataConverter, ref other.dataConverter);
69+
ApplyIfSet(this.enableEntitySupport, ref other.enableEntitySupport);
70+
}
71+
}
9372

94-
if (!other.EntitySupportExplicitlySet)
95-
{
96-
other.EnableEntitySupport = this.EnableEntitySupport;
97-
}
73+
static void ApplyIfSet<T>(T? value, ref T? target)
74+
{
75+
if (value is not null && target is null)
76+
{
77+
target = value;
9878
}
9979
}
10080
}

src/Worker/Core/DurableTaskWorkerOptions.cs

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ namespace Microsoft.DurableTask.Worker;
1010
/// </summary>
1111
public class DurableTaskWorkerOptions
1212
{
13-
DataConverter dataConverter = JsonDataConverter.Default;
13+
DataConverter? dataConverter;
14+
bool? enableEntitySupport;
15+
TimeSpan? maximumTimerInterval;
1416

1517
/// <summary>
1618
/// Gets or sets the data converter. Default value is <see cref="JsonDataConverter.Default" />.
@@ -28,27 +30,19 @@ public class DurableTaskWorkerOptions
2830
/// </remarks>
2931
public DataConverter DataConverter
3032
{
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;
4535
}
4636

4737
/// <summary>
4838
/// Gets or sets a value indicating whether this client should support entities. If true, all instance ids starting
4939
/// with '@' are reserved for entities, and validation checks are performed where appropriate.
5040
/// </summary>
51-
public bool EnableEntitySupport { get; set; }
41+
public bool EnableEntitySupport
42+
{
43+
get => this.enableEntitySupport ?? false;
44+
set => this.enableEntitySupport = value;
45+
}
5246

5347
/// <summary>
5448
/// Gets or sets the maximum timer interval for the
@@ -81,7 +75,11 @@ public DataConverter DataConverter
8175
/// orchestrations.
8276
/// </para>
8377
/// </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+
}
8583

8684
/// <summary>
8785
/// Gets options for the Durable Task worker concurrency.
@@ -102,7 +100,7 @@ public DataConverter DataConverter
102100
/// will <b>not</b> resolve it. If not set, we will attempt to resolve it. This is so the
103101
/// behavior is consistently irrespective of option configuration ordering.
104102
/// </remarks>
105-
internal bool DataConverterExplicitlySet { get; private set; }
103+
internal bool DataConverterExplicitlySet => this.dataConverter is not null;
106104

107105
/// <summary>
108106
/// Applies these option values to another.
@@ -113,9 +111,18 @@ internal void ApplyTo(DurableTaskWorkerOptions other)
113111
if (other is not null)
114112
{
115113
// 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;
119126
}
120127
}
121128

@@ -124,19 +131,51 @@ internal void ApplyTo(DurableTaskWorkerOptions other)
124131
/// </summary>
125132
public class ConcurrencyOptions
126133
{
134+
static readonly int DefaultMaxConcurrency = 100 * Environment.ProcessorCount;
135+
136+
int? maxActivity;
137+
int? maxOrchestration;
138+
int? maxEntity;
139+
127140
/// <summary>
128141
/// Gets or sets the maximum number of concurrent activity work items that can be processed by the worker.
129142
/// </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+
}
131148

132149
/// <summary>
133150
/// Gets or sets the maximum number of concurrent orchestration work items that can be processed by the worker.
134151
/// </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+
}
136157

137158
/// <summary>
138159
/// Gets or sets the maximum number of concurrent entity work items that can be processed by the worker.
139160
/// </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+
}
141180
}
142181
}

0 commit comments

Comments
 (0)