mirror of https://github.com/dapr/dotnet-sdk.git
Add an option to set Timeout for ActorProxy (#748)
* Add an option to set Timeout for ActorProxy Actors, by there nature, may have to wait for a long period before being allowed to execute. This could lead to long request times. The default timeout for the HttpClient being used is fairly low. This commit allows for the timeout to be set when constructing the proxy. https://github.com/dapr/dotnet-sdk/issues/728 * Removed extra constructor and e2e tests.
This commit is contained in:
parent
aba49d1446
commit
cee49bff92
|
@ -58,7 +58,7 @@ namespace Dapr.Actors.Client
|
|||
options ??= this.DefaultOptions;
|
||||
|
||||
var actorProxy = new ActorProxy();
|
||||
var daprInteractor = new DaprHttpInteractor(this.handler, options.HttpEndpoint, options.DaprApiToken);
|
||||
var daprInteractor = new DaprHttpInteractor(this.handler, options.HttpEndpoint, options.DaprApiToken, options.RequestTimeout);
|
||||
var nonRemotingClient = new ActorNonRemotingClient(daprInteractor);
|
||||
actorProxy.Initialize(nonRemotingClient, actorId, actorType, options);
|
||||
|
||||
|
@ -70,7 +70,7 @@ namespace Dapr.Actors.Client
|
|||
{
|
||||
options ??= this.DefaultOptions;
|
||||
|
||||
var daprInteractor = new DaprHttpInteractor(this.handler, options.HttpEndpoint, options.DaprApiToken);
|
||||
var daprInteractor = new DaprHttpInteractor(this.handler, options.HttpEndpoint, options.DaprApiToken, options.RequestTimeout);
|
||||
var remotingClient = new ActorRemotingClient(daprInteractor);
|
||||
var proxyGenerator = ActorCodeBuilder.GetOrCreateProxyGenerator(actorInterfaceType);
|
||||
var actorProxy = proxyGenerator.CreateActorProxy();
|
||||
|
|
|
@ -49,5 +49,10 @@ namespace Dapr.Actors.Client
|
|||
/// </remarks>
|
||||
/// <value></value>
|
||||
public string HttpEndpoint { get; set; } = DaprDefaults.GetDefaultHttpEndpoint();
|
||||
|
||||
/// <summary>
|
||||
/// The timeout allowed for an actor request. Can be set to System.Threading.Timeout.InfiniteTimeSpan to disable any timeouts.
|
||||
/// </summary>
|
||||
public TimeSpan? RequestTimeout { get; set; } = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,12 +36,14 @@ namespace Dapr.Actors
|
|||
public DaprHttpInteractor(
|
||||
HttpMessageHandler clientHandler,
|
||||
string httpEndpoint,
|
||||
string apiToken)
|
||||
string apiToken,
|
||||
TimeSpan? requestTimeout)
|
||||
{
|
||||
this.handler = clientHandler ?? defaultHandler;
|
||||
this.httpEndpoint = httpEndpoint;
|
||||
this.daprApiToken = apiToken;
|
||||
this.httpClient = this.CreateHttpClient();
|
||||
this.httpClient.Timeout = requestTimeout ?? this.httpClient.Timeout;
|
||||
}
|
||||
|
||||
public async Task<string> GetStateAsync(string actorType, string actorId, string keyName, CancellationToken cancellationToken = default)
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace Dapr.Actors.Runtime
|
|||
// Revisit this if actor initialization becomes a significant source of delay for large projects.
|
||||
foreach (var actor in options.Actors)
|
||||
{
|
||||
var daprInteractor = new DaprHttpInteractor(clientHandler: null, httpEndpoint: options.HttpEndpoint, apiToken: options.DaprApiToken);
|
||||
var daprInteractor = new DaprHttpInteractor(clientHandler: null, httpEndpoint: options.HttpEndpoint, apiToken: options.DaprApiToken, requestTimeout: null);
|
||||
this.actorManagers[actor.Type.ActorTypeName] = new ActorManager(
|
||||
actor,
|
||||
actor.Activator ?? this.activatorFactory.CreateActivator(actor.Type),
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Dapr.Actors.Runtime
|
|||
private ActorManager CreateActorManager(Type type, ActorActivator activator = null)
|
||||
{
|
||||
var registration = new ActorRegistration(ActorTypeInformation.Get(type));
|
||||
var interactor = new DaprHttpInteractor(clientHandler: null, "http://localhost:3500", apiToken: null);
|
||||
var interactor = new DaprHttpInteractor(clientHandler: null, "http://localhost:3500", apiToken: null, requestTimeout: null);
|
||||
return new ActorManager(registration, activator ?? new DefaultActorActivator(), JsonSerializerDefaults.Web, NullLoggerFactory.Instance, ActorProxy.DefaultProxyFactory, interactor);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace Dapr
|
|||
internal static TestClient<DaprHttpInteractor> CreateForDaprHttpInterator(string? apiToken = null)
|
||||
{
|
||||
var handler = new CapturingHandler();
|
||||
return new TestClient<DaprHttpInteractor>(new DaprHttpInteractor(handler, "http://localhost:3500", apiToken), handler);
|
||||
return new TestClient<DaprHttpInteractor>(new DaprHttpInteractor(handler, "http://localhost:3500", apiToken, null), handler);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue