Skip to content

Commit f129411

Browse files
committed
Remove unneeded constructors, make options public
Signed-off-by: Hal Spang <[email protected]>
1 parent daad88c commit f129411

File tree

4 files changed

+30
-85
lines changed

4 files changed

+30
-85
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## (Unreleased)
44

5+
- Expose gRPC retry options in Azure Managed extensions ([#447](https://github.com/microsoft/durabletask-dotnet/pull/447))
6+
57
## v1.12.0
68

79
- Activity tag support ([#426](https://github.com/microsoft/durabletask-dotnet/pull/426))

src/Client/AzureManaged/DurableTaskSchedulerClientExtensions.cs

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -40,70 +40,15 @@ public static void UseDurableTaskScheduler(
4040
configure);
4141
}
4242

43-
/// <summary>
44-
/// Configures Durable Task client to use the Azure Durable Task Scheduler service.
45-
/// </summary>
46-
/// <param name="builder">The Durable Task client builder to configure.</param>
47-
/// <param name="endpointAddress">The endpoint address of the Durable Task Scheduler resource. Expected to be in the format "https://{scheduler-name}.{region}.durabletask.io".</param>
48-
/// <param name="taskHubName">The name of the task hub resource associated with the Durable Task Scheduler resource.</param>
49-
/// <param name="credential">The credential used to authenticate with the Durable Task Scheduler task hub resource.</param>
50-
/// <param name="retryOptions">The options that determine how and when a request will be retried.</param>
51-
/// <param name="configure">Optional callback to dynamically configure DurableTaskSchedulerClientOptions.</param>
52-
public static void UseDurableTaskScheduler(
53-
this IDurableTaskClientBuilder builder,
54-
string endpointAddress,
55-
string taskHubName,
56-
TokenCredential credential,
57-
DurableTaskSchedulerClientOptions.ClientRetryOptions retryOptions,
58-
Action<DurableTaskSchedulerClientOptions>? configure = null)
59-
{
60-
ConfigureSchedulerOptions(
61-
builder,
62-
options =>
63-
{
64-
options.EndpointAddress = endpointAddress;
65-
options.TaskHubName = taskHubName;
66-
options.Credential = credential;
67-
options.RetryOptions = retryOptions;
68-
},
69-
configure);
70-
}
71-
72-
/// <summary>
73-
/// Configures Durable Task client to use the Azure Durable Task Scheduler service using a connection string.
74-
/// </summary>
75-
/// <param name="builder">The Durable Task client builder to configure.</param>
76-
/// <param name="connectionString">The connection string used to connect to the Durable Task Scheduler service.</param>
77-
/// <param name="configure">Optional callback to dynamically configure DurableTaskSchedulerClientOptions.</param>
78-
public static void UseDurableTaskScheduler(
79-
this IDurableTaskClientBuilder builder,
80-
string connectionString,
81-
Action<DurableTaskSchedulerClientOptions>? configure = null)
82-
{
83-
var connectionOptions = DurableTaskSchedulerClientOptions.FromConnectionString(connectionString);
84-
ConfigureSchedulerOptions(
85-
builder,
86-
options =>
87-
{
88-
options.EndpointAddress = connectionOptions.EndpointAddress;
89-
options.TaskHubName = connectionOptions.TaskHubName;
90-
options.Credential = connectionOptions.Credential;
91-
options.AllowInsecureCredentials = connectionOptions.AllowInsecureCredentials;
92-
},
93-
configure);
94-
}
95-
9643
/// <summary>
9744
/// Configures Durable Task client to use the Azure Durable Task Scheduler service using a connection string.
9845
/// </summary>
9946
/// <param name="builder">The Durable Task client builder to configure.</param>
10047
/// <param name="connectionString">The connection string used to connect to the Durable Task Scheduler service.</param>
101-
/// /// <param name="retryOptions">The options that determine how and when a request will be retried.</param>
10248
/// <param name="configure">Optional callback to dynamically configure DurableTaskSchedulerClientOptions.</param>
10349
public static void UseDurableTaskScheduler(
10450
this IDurableTaskClientBuilder builder,
10551
string connectionString,
106-
DurableTaskSchedulerClientOptions.ClientRetryOptions retryOptions,
10752
Action<DurableTaskSchedulerClientOptions>? configure = null)
10853
{
10954
var connectionOptions = DurableTaskSchedulerClientOptions.FromConnectionString(connectionString);
@@ -115,7 +60,6 @@ public static void UseDurableTaskScheduler(
11560
options.TaskHubName = connectionOptions.TaskHubName;
11661
options.Credential = connectionOptions.Credential;
11762
options.AllowInsecureCredentials = connectionOptions.AllowInsecureCredentials;
118-
options.RetryOptions = retryOptions;
11963
},
12064
configure);
12165
}

src/Client/AzureManaged/DurableTaskSchedulerClientOptions.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Grpc.Core;
88
using Grpc.Net.Client;
99
using Microsoft.DurableTask.Client;
10-
using grpcConfig = Grpc.Net.Client.Configuration;
10+
using GrpcConfig = Grpc.Net.Client.Configuration;
1111

1212
namespace Microsoft.DurableTask;
1313

@@ -49,7 +49,7 @@ public class DurableTaskSchedulerClientOptions
4949
/// <summary>
5050
/// Gets or sets the options that determine how and when calls made to the scheduler will be retried.
5151
/// </summary>
52-
internal ClientRetryOptions? RetryOptions { get; set; }
52+
public ClientRetryOptions? RetryOptions { get; set; }
5353

5454
/// <summary>
5555
/// Creates a new instance of <see cref="DurableTaskSchedulerClientOptions"/> from a connection string.
@@ -114,10 +114,10 @@ this.Credential is not null
114114
metadata.Add("Authorization", $"Bearer {token.Token}");
115115
});
116116

117-
grpcConfig.ServiceConfig? serviceConfig = null;
117+
GrpcConfig.ServiceConfig? serviceConfig = GrpcRetryPolicyDefaults.DefaultServiceConfig;
118118
if (this.RetryOptions != null)
119119
{
120-
grpcConfig.RetryPolicy retryPolicy = new grpcConfig.RetryPolicy
120+
GrpcConfig.RetryPolicy retryPolicy = new GrpcConfig.RetryPolicy
121121
{
122122
MaxAttempts = this.RetryOptions.MaxRetries ?? GrpcRetryPolicyDefaults.DefaultMaxAttempts,
123123
InitialBackoff = TimeSpan.FromMilliseconds(this.RetryOptions.InitialBackoffMs ?? GrpcRetryPolicyDefaults.DefaultInitialBackoffMs),
@@ -140,21 +140,18 @@ this.Credential is not null
140140
}
141141
}
142142

143-
grpcConfig.MethodConfig methodConfig = new grpcConfig.MethodConfig
143+
GrpcConfig.MethodConfig methodConfig = new GrpcConfig.MethodConfig
144144
{
145-
Names = { grpcConfig.MethodName.Default },
145+
// MethodName.Default applies this retry policy configuration to all gRPC methods on the channel.
146+
Names = { GrpcConfig.MethodName.Default },
146147
RetryPolicy = retryPolicy,
147148
};
148149

149-
serviceConfig = new grpcConfig.ServiceConfig
150+
serviceConfig = new GrpcConfig.ServiceConfig
150151
{
151152
MethodConfigs = { methodConfig },
152153
};
153154
}
154-
else
155-
{
156-
serviceConfig = GrpcRetryPolicyDefaults.DefaultServiceConfig;
157-
}
158155

159156
// Production will use HTTPS, but local testing will use HTTP
160157
ChannelCredentials channelCreds = endpoint.StartsWith("https://", StringComparison.OrdinalIgnoreCase) ?

test/Client/AzureManaged.Tests/DurableTaskSchedulerClientExtensionsTests.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,16 @@ public void UseDurableTaskScheduler_WithEndpointAndCredentialAndRetryOptions_Sho
205205
DefaultAzureCredential credential = new DefaultAzureCredential();
206206

207207
// Act
208-
mockBuilder.Object.UseDurableTaskScheduler(ValidEndpoint, ValidTaskHub, credential,
209-
new DurableTaskSchedulerClientOptions.ClientRetryOptions
210-
{
211-
MaxRetries = 5,
212-
InitialBackoffMs = 100,
213-
MaxBackoffMs = 1000,
214-
BackoffMultiplier = 2.0,
215-
RetryableStatusCodes = new List<StatusCode> { StatusCode.Unknown }
216-
});
208+
mockBuilder.Object.UseDurableTaskScheduler(ValidEndpoint, ValidTaskHub, credential, options =>
209+
options.RetryOptions = new DurableTaskSchedulerClientOptions.ClientRetryOptions
210+
{
211+
MaxRetries = 5,
212+
InitialBackoffMs = 100,
213+
MaxBackoffMs = 1000,
214+
BackoffMultiplier = 2.0,
215+
RetryableStatusCodes = new List<StatusCode> { StatusCode.Unknown }
216+
}
217+
);
217218

218219
// Assert
219220
ServiceProvider provider = services.BuildServiceProvider();
@@ -247,15 +248,16 @@ public void UseDurableTaskScheduler_WithConnectionStringAndRetryOptions_ShouldCo
247248
string connectionString = $"Endpoint={ValidEndpoint};Authentication=DefaultAzure;TaskHub={ValidTaskHub}";
248249

249250
// Act
250-
mockBuilder.Object.UseDurableTaskScheduler(connectionString,
251-
new DurableTaskSchedulerClientOptions.ClientRetryOptions
252-
{
253-
MaxRetries = 5,
254-
InitialBackoffMs = 100,
255-
MaxBackoffMs = 1000,
256-
BackoffMultiplier = 2.0,
257-
RetryableStatusCodes = new List<StatusCode> { StatusCode.Unknown }
258-
});
251+
mockBuilder.Object.UseDurableTaskScheduler(connectionString, options =>
252+
options.RetryOptions = new DurableTaskSchedulerClientOptions.ClientRetryOptions
253+
{
254+
MaxRetries = 5,
255+
InitialBackoffMs = 100,
256+
MaxBackoffMs = 1000,
257+
BackoffMultiplier = 2.0,
258+
RetryableStatusCodes = new List<StatusCode> { StatusCode.Unknown }
259+
}
260+
);
259261

260262
// Assert
261263
ServiceProvider provider = services.BuildServiceProvider();

0 commit comments

Comments
 (0)