From b88addb5f52e48cd76f2d8b89f72c821e50afdaa Mon Sep 17 00:00:00 2001 From: SonicGD Date: Wed, 14 Aug 2024 16:46:51 +0500 Subject: [PATCH 1/2] feat: configure default grpc calls deadline --- src/Sitko.Core.Grpc.Client/GrpcClientModule.cs | 14 +++++++++++++- .../GrpcClientModuleOptions.cs | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Sitko.Core.Grpc.Client/GrpcClientModule.cs b/src/Sitko.Core.Grpc.Client/GrpcClientModule.cs index 449e73ad2..9b570a118 100644 --- a/src/Sitko.Core.Grpc.Client/GrpcClientModule.cs +++ b/src/Sitko.Core.Grpc.Client/GrpcClientModule.cs @@ -26,10 +26,22 @@ public override void ConfigureServices(IApplicationContext applicationContext, I "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); } + services.TryAddSingleton(TimeProvider.System); services.TryAddSingleton>(); services.TryAddSingleton(); services.TryAddTransient(); - var builder = services.AddGrpcClient(); + var builder = services.AddGrpcClient((provider, options) => + { + options.CallOptionsActions.Add(context => + { + if (startupOptions.DefaultDeadline is not null) + { + context.CallOptions = context.CallOptions.WithDeadline(provider.GetRequiredService() + .GetUtcNow() + .Add(startupOptions.DefaultDeadline.Value).DateTime); + } + }); + }); services.AddTransient, GrpcClientProvider>(); RegisterResolver(services, startupOptions); startupOptions.ConfigureClient(services, builder); diff --git a/src/Sitko.Core.Grpc.Client/GrpcClientModuleOptions.cs b/src/Sitko.Core.Grpc.Client/GrpcClientModuleOptions.cs index 5116b4b76..af6e7abe1 100644 --- a/src/Sitko.Core.Grpc.Client/GrpcClientModuleOptions.cs +++ b/src/Sitko.Core.Grpc.Client/GrpcClientModuleOptions.cs @@ -17,6 +17,7 @@ public class GrpcClientModuleOptions : BaseModuleOptions where TClient private readonly List> configureServicesActions = new(); public bool EnableHttp2UnencryptedSupport { get; set; } public bool DisableCertificatesValidation { get; set; } + public TimeSpan? DefaultDeadline { get; set; } = TimeSpan.FromMinutes(30); [JsonIgnore] public Action? ConfigureChannelOptions { get; set; } [JsonIgnore] public Func? ConfigureHttpHandler { get; set; } From 821da4d27f4435a9e3a25133af026cb7019b2954 Mon Sep 17 00:00:00 2001 From: nadia Date: Wed, 14 Aug 2024 17:30:13 +0500 Subject: [PATCH 2/2] fix: use UtcDateTime to deadline --- src/Sitko.Core.Grpc.Client/GrpcClientModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sitko.Core.Grpc.Client/GrpcClientModule.cs b/src/Sitko.Core.Grpc.Client/GrpcClientModule.cs index 9b570a118..90d8b43de 100644 --- a/src/Sitko.Core.Grpc.Client/GrpcClientModule.cs +++ b/src/Sitko.Core.Grpc.Client/GrpcClientModule.cs @@ -38,7 +38,7 @@ public override void ConfigureServices(IApplicationContext applicationContext, I { context.CallOptions = context.CallOptions.WithDeadline(provider.GetRequiredService() .GetUtcNow() - .Add(startupOptions.DefaultDeadline.Value).DateTime); + .Add(startupOptions.DefaultDeadline.Value).UtcDateTime); } }); });