mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-12 21:17:23 +01:00
add retry policy for grpc clients
This commit is contained in:
parent
77e4602d2f
commit
2f1ef04f6a
3 changed files with 42 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ using AspNetCoreRateLimit;
|
|||
using MareSynchronosShared.Authentication;
|
||||
using MareSynchronosShared.Data;
|
||||
using MareSynchronosShared.Protos;
|
||||
using Grpc.Net.Client.Configuration;
|
||||
|
||||
namespace MareSynchronosServer
|
||||
{
|
||||
|
|
@ -46,17 +47,38 @@ namespace MareSynchronosServer
|
|||
|
||||
var mareConfig = Configuration.GetRequiredSection("MareSynchronos");
|
||||
|
||||
var defaultMethodConfig = new MethodConfig
|
||||
{
|
||||
Names = { MethodName.Default },
|
||||
RetryPolicy = new RetryPolicy
|
||||
{
|
||||
MaxAttempts = 100,
|
||||
InitialBackoff = TimeSpan.FromSeconds(1),
|
||||
MaxBackoff = TimeSpan.FromSeconds(5),
|
||||
BackoffMultiplier = 1.5,
|
||||
}
|
||||
};
|
||||
|
||||
services.AddGrpcClient<AuthService.AuthServiceClient>(c =>
|
||||
{
|
||||
c.Address = new Uri(mareConfig.GetValue<string>("ServiceAddress"));
|
||||
}).ConfigureChannel(c =>
|
||||
{
|
||||
c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } };
|
||||
});
|
||||
services.AddGrpcClient<MetricsService.MetricsServiceClient>(c =>
|
||||
{
|
||||
c.Address = new Uri(mareConfig.GetValue<string>("ServiceAddress"));
|
||||
}).ConfigureChannel(c =>
|
||||
{
|
||||
c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } };
|
||||
});
|
||||
services.AddGrpcClient<FileService.FileServiceClient>(c =>
|
||||
{
|
||||
c.Address = new Uri(mareConfig.GetValue<string>("StaticFileServiceAddress"));
|
||||
}).ConfigureChannel(c =>
|
||||
{
|
||||
c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } };
|
||||
});
|
||||
|
||||
services.AddDbContextPool<MareDbContext>(options =>
|
||||
|
|
|
|||
|
|
@ -484,6 +484,7 @@ public class DiscordBot : IHostedService
|
|||
vanityUpdateCts = new();
|
||||
while (!vanityUpdateCts.IsCancellationRequested)
|
||||
{
|
||||
logger.LogInformation($"Cleaning up Vanity UIDs");
|
||||
var guild = discordClient.Guilds.FirstOrDefault();
|
||||
if (guild == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using Grpc.Net.Client.Configuration;
|
||||
using MareSynchronosShared.Authentication;
|
||||
using MareSynchronosShared.Data;
|
||||
using MareSynchronosShared.Protos;
|
||||
|
|
@ -30,13 +31,31 @@ public class Startup
|
|||
|
||||
var mareSettings = Configuration.GetRequiredSection("MareSynchronos");
|
||||
|
||||
var defaultMethodConfig = new MethodConfig
|
||||
{
|
||||
Names = { MethodName.Default },
|
||||
RetryPolicy = new RetryPolicy
|
||||
{
|
||||
MaxAttempts = 100,
|
||||
InitialBackoff = TimeSpan.FromSeconds(1),
|
||||
MaxBackoff = TimeSpan.FromSeconds(5),
|
||||
BackoffMultiplier = 1.5,
|
||||
}
|
||||
};
|
||||
|
||||
services.AddGrpcClient<AuthService.AuthServiceClient>(c =>
|
||||
{
|
||||
c.Address = new Uri(mareSettings.GetValue<string>("ServiceAddress"));
|
||||
}).ConfigureChannel(c =>
|
||||
{
|
||||
c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } };
|
||||
});
|
||||
services.AddGrpcClient<MetricsService.MetricsServiceClient>(c =>
|
||||
{
|
||||
c.Address = new Uri(mareSettings.GetValue<string>("ServiceAddress"));
|
||||
}).ConfigureChannel(c =>
|
||||
{
|
||||
c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } };
|
||||
});
|
||||
|
||||
services.AddDbContextPool<MareDbContext>(options =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue