Created CertificationTrainingGroupWorker
This commit is contained in:
@ -9,26 +9,26 @@ using System.Text;
|
||||
|
||||
namespace FabApprovalWorkerService.Workers;
|
||||
|
||||
public class UserCertificationWorker : IJob {
|
||||
public class CertificationTrainingGroupWorker : IJob {
|
||||
private static readonly int MAX_RETRIES = 3;
|
||||
private static readonly int BACKOFF_SECONDS = 30;
|
||||
|
||||
private readonly ILogger<UserCertificationWorker> _logger;
|
||||
private readonly IUserService _userService;
|
||||
private readonly ILogger<CertificationTrainingGroupWorker> _logger;
|
||||
private readonly ITrainingService _trainingService;
|
||||
private readonly IMonInClient _monInClient;
|
||||
|
||||
public UserCertificationWorker(ILogger<UserCertificationWorker> logger,
|
||||
IUserService userService,
|
||||
public CertificationTrainingGroupWorker(ILogger<CertificationTrainingGroupWorker> logger,
|
||||
ITrainingService trainingService,
|
||||
IMonInClient monInClient) {
|
||||
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
||||
_userService = userService ?? throw new ArgumentNullException("IUserService not injected");
|
||||
_trainingService = trainingService ?? throw new ArgumentNullException("ITrainingService not injected");
|
||||
_monInClient = monInClient ?? throw new ArgumentNullException("IMonInClient not injected");
|
||||
}
|
||||
|
||||
public async Task Execute(IJobExecutionContext context) {
|
||||
DateTime start = DateTime.Now;
|
||||
bool isInternalError = false;
|
||||
string metricName = "UserCertificationWorker";
|
||||
string metricName = "CertificationTrainingGroupWorker";
|
||||
|
||||
try {
|
||||
int remainingRetries = MAX_RETRIES;
|
||||
@ -37,20 +37,20 @@ public class UserCertificationWorker : IJob {
|
||||
while (!isSuccessful && remainingRetries > 0) {
|
||||
await Task.Delay((MAX_RETRIES - remainingRetries--) * BACKOFF_SECONDS);
|
||||
|
||||
_logger.LogInformation($"Attempting to update user certification data. Remaining retries: {remainingRetries}");
|
||||
_logger.LogInformation($"Attempting to update certification training group membership. Remaining retries: {remainingRetries}");
|
||||
|
||||
IEnumerable<UserCertificationRecord> certRecords = await _userService.GetUserCertificationRecords();
|
||||
isSuccessful = await _userService.UpdateUserCertificationData(certRecords);
|
||||
IEnumerable<UserCertificationRecord> certRecords = await _trainingService.GetUserCertificationRecords();
|
||||
isSuccessful = await _trainingService.UpdateTrainingGroupMembership(certRecords);
|
||||
}
|
||||
|
||||
if (isSuccessful) {
|
||||
_logger.LogInformation("Successfully updated user certification data.");
|
||||
_logger.LogInformation("Successfully updated certification training group membership.");
|
||||
} else {
|
||||
throw new Exception("Unable to update user certification data.");
|
||||
throw new Exception("Unable to update certification training group membership.");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
StringBuilder errMsgBuilder = new();
|
||||
errMsgBuilder.Append("An exception occurred when attempting to update user certification data. ");
|
||||
errMsgBuilder.Append("An exception occurred when attempting to update certification training group membership. ");
|
||||
errMsgBuilder.Append($"Exception: {ex.Message}");
|
||||
_logger.LogError(errMsgBuilder.ToString());
|
||||
isInternalError = true;
|
Reference in New Issue
Block a user