fix: enhance database context configuration with retry logic for resilience
Some checks failed
release-dev / release-dev (push) Failing after 14s

This commit is contained in:
Suphonchai Phoonsawat 2025-12-15 11:12:29 +07:00
parent ff66aebdfa
commit 18ab28e335
2 changed files with 21 additions and 10 deletions

View file

@ -20,8 +20,6 @@ namespace BMA.EHR.Infrastructure
public static IServiceCollection AddLeavePersistence(this IServiceCollection services,
IConfiguration configuration)
{
// leave db context
var connectionStringLeave = configuration.GetConnectionString("LeaveConnection");
@ -31,6 +29,10 @@ namespace BMA.EHR.Infrastructure
{
b.MigrationsAssembly(typeof(LeaveDbContext).Assembly.FullName);
b.MigrationsHistoryTable("__LeaveMigrationsHistory");
b.EnableRetryOnFailure(
maxRetryCount: 5,
maxRetryDelay: System.TimeSpan.FromSeconds(30),
errorNumbersToAdd: null);
}),
ServiceLifetime.Transient);
@ -43,8 +45,6 @@ namespace BMA.EHR.Infrastructure
public static IServiceCollection AddDisciplinePersistence(this IServiceCollection services,
IConfiguration configuration)
{
// discipline db context
var connectionStringDiscipline = configuration.GetConnectionString("DisciplineConnection");
@ -54,7 +54,10 @@ namespace BMA.EHR.Infrastructure
{
b.MigrationsAssembly(typeof(DisciplineDbContext).Assembly.FullName);
b.MigrationsHistoryTable("__DisciplineMigrationsHistory");
b.EnableRetryOnFailure(
maxRetryCount: 5,
maxRetryDelay: System.TimeSpan.FromSeconds(30),
errorNumbersToAdd: null);
}),
ServiceLifetime.Transient);
@ -67,8 +70,6 @@ namespace BMA.EHR.Infrastructure
IConfiguration configuration)
{
services.AddTransient<MinIOService>();
var connectionString = configuration.GetConnectionString("DefaultConnection");
services.AddDbContext<ApplicationDBContext>(options =>
@ -77,9 +78,14 @@ namespace BMA.EHR.Infrastructure
{
b.MigrationsAssembly(typeof(ApplicationDBContext).Assembly.FullName);
b.MigrationsHistoryTable("__EHRMigrationsHistory");
b.EnableRetryOnFailure(
maxRetryCount: 5,
maxRetryDelay: System.TimeSpan.FromSeconds(30),
errorNumbersToAdd: null);
}),
ServiceLifetime.Transient);
services.AddTransient<IApplicationDBContext>(provider => provider.GetService<ApplicationDBContext>());
@ -91,6 +97,10 @@ namespace BMA.EHR.Infrastructure
{
b.MigrationsAssembly(typeof(ApplicationDBExamContext).Assembly.FullName);
b.MigrationsHistoryTable("__EHRMigrationsHistory");
b.EnableRetryOnFailure(
maxRetryCount: 5,
maxRetryDelay: System.TimeSpan.FromSeconds(30),
errorNumbersToAdd: null);
}),
ServiceLifetime.Transient);