feat: add database worker with timer for building database at start up and refreshing once every hour.

This commit is contained in:
Stevan Freeborn
2024-08-25 16:31:12 -05:00
parent 674712db9d
commit a173220e51
8 changed files with 121 additions and 29 deletions
@@ -1,6 +1,6 @@
namespace SanctionsSearch.Worker.Persistence;
class EfUnitOfWork(DbContext context, ILoggerFactory loggerFactory) : IUnitOfWork, IAsyncDisposable
class EfUnitOfWork(DbContext context, ILoggerFactory loggerFactory) : IUnitOfWork, IAsyncDisposable, IDisposable
{
private readonly DbContext _context = context;
private readonly ILogger<EfUnitOfWork> _logger = loggerFactory.CreateLogger<EfUnitOfWork>();
@@ -32,4 +32,16 @@ class EfUnitOfWork(DbContext context, ILoggerFactory loggerFactory) : IUnitOfWor
_logger.LogError(ex, "Failed to dispose of the database context.");
}
}
public void Dispose()
{
try
{
_context.Dispose();
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to dispose of the database context.");
}
}
}