Created ExpiredOOOStatusWorker

This commit is contained in:
Chase Tucker
2024-03-25 12:22:26 -07:00
parent 27f78da969
commit 69fdd98ab3
46 changed files with 549 additions and 5118 deletions

View File

@ -1,7 +1,4 @@
using Dapper;
using Dapper.Contrib.Extensions;
using FabApprovalWorkerService.Models;
using System.Data;
@ -16,14 +13,14 @@ public class DalService : IDalService {
private static readonly int RETRIES = 3;
private static readonly int BACKOFF_SECONDS_INTERVAL = 30;
private readonly IDbConnection _dbConnection;
private readonly IDbConnectionService _connectionPoolService;
private readonly ILogger<DalService> _logger;
public DalService(IDbConnection dbConnection, ILogger<DalService> logger) {
_dbConnection = dbConnection;
if (_dbConnection is null) throw new ArgumentNullException("IDbConnection not injected");
_logger = logger;
if (_logger is null) throw new ArgumentNullException("ILogger not injected");
public DalService(IDbConnectionService connectionPoolService, ILogger<DalService> logger) {
_connectionPoolService = connectionPoolService ??
throw new ArgumentNullException("IConnectionPoolService not injected");
_logger = logger ??
throw new ArgumentNullException("ILogger not injected");
}
public async Task<IEnumerable<T>> QueryAsync<T>(string sql) {
@ -38,19 +35,15 @@ public class DalService : IDalService {
Task.Delay(backoffSeconds * 1000).Wait();
try {
_logger.LogInformation("Attempting to perform query with {sql}. Remaining retries: {remainingRetries}",
sql,
remainingRetries);
_logger.LogInformation($"Attempting to perform query with {sql}. Remaining retries: {remainingRetries}");
using (_dbConnection) {
result = await _dbConnection.QueryAsync<T>(sql);
using (IDbConnection conn = _connectionPoolService.GetConnection()) {
result = await conn.QueryAsync<T>(sql);
}
queryWasSuccessful = true;
} catch (Exception ex) {
_logger.LogError("An exception occurred while attempting to perform a query. Exception: {ex}",
ex.Message);
_logger.LogError($"An exception occurred while attempting to perform a query. Exception: {ex.Message}");
exception = ex;
}
}
@ -74,19 +67,15 @@ public class DalService : IDalService {
Task.Delay(backoffSeconds * 1000).Wait();
try {
_logger.LogInformation("Attempting to execute {sql}. Remaining retries: {remainingRetries}",
sql,
remainingRetries);
_logger.LogInformation($"Attempting to execute {sql}. Remaining retries: {remainingRetries}");
using (_dbConnection) {
rowsAffected = await _dbConnection.ExecuteAsync(sql);
using (IDbConnection conn = _connectionPoolService.GetConnection()) {
rowsAffected = await conn.ExecuteAsync(sql);
}
queryWasSuccessful = true;
} catch (Exception ex) {
_logger.LogError("An exception occurred while attempting to execute a query. Exception: {ex}",
ex.Message);
_logger.LogError($"An exception occurred while attempting to execute a query. Exception: {ex.Message}");
exception = ex;
}
}