Switched to standard MonIn library
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Services;
|
||||
|
||||
using Infineon.Monitoring.MonA;
|
||||
|
||||
using Quartz;
|
||||
|
||||
using System.Net.Mail;
|
||||
@ -10,26 +12,29 @@ namespace FabApprovalWorkerService.Workers;
|
||||
|
||||
public class ExpiringTECNWorker : IJob {
|
||||
private readonly ILogger<ExpiringTECNWorker> _logger;
|
||||
private readonly IMonInWorkerClient _monInClient;
|
||||
private readonly IMonInClient _monInClient;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IECNService _ecnService;
|
||||
private readonly ISmtpService _smtpService;
|
||||
private readonly string _baseUrl;
|
||||
|
||||
public ExpiringTECNWorker(ILogger<ExpiringTECNWorker> logger,
|
||||
IMonInWorkerClient monInClient,
|
||||
IMonInClient monInClient,
|
||||
IUserService userService,
|
||||
IECNService ecnService,
|
||||
ISmtpService smtpService) {
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException("ILogger not injected");
|
||||
_monInClient = monInClient ??
|
||||
throw new ArgumentNullException("IMonInWorkerClient not injected");
|
||||
throw new ArgumentNullException("IMonInClient not injected");
|
||||
_userService = userService ??
|
||||
throw new ArgumentNullException("IUserService not injected");
|
||||
_ecnService = ecnService ??
|
||||
throw new ArgumentNullException("IECNService not injected");
|
||||
_smtpService = smtpService ??
|
||||
throw new ArgumentNullException("ISmtpService not injected");
|
||||
_baseUrl = Environment.GetEnvironmentVariable("FabApprovalBaseUrl") ??
|
||||
throw new ArgumentNullException("FabApprovalBaseUrl environment variable not found");
|
||||
}
|
||||
|
||||
public async Task Execute(IJobExecutionContext context) {
|
||||
@ -45,12 +50,15 @@ public class ExpiringTECNWorker : IJob {
|
||||
|
||||
_logger.LogInformation($"There are {expiringTECNs.Count()} TECNs expiring in the next 5 days");
|
||||
|
||||
IEnumerable<string> tecnNotificationUserEmails = new List<string>();
|
||||
if (expiringTECNs.Any())
|
||||
tecnNotificationUserEmails = await _ecnService.GetTECNNotificationUserEmails();
|
||||
|
||||
foreach (ECN eCN in expiringTECNs) {
|
||||
string recipientEmail = await _userService.GetUserEmail(eCN.OriginatorID);
|
||||
MailAddress recipientAddress = new MailAddress(recipientEmail);
|
||||
List<MailAddress> recipientList = new () { recipientAddress };
|
||||
|
||||
IEnumerable<string> tecnNotificationUserEmails = await _ecnService.GetTECNNotificationUserEmails();
|
||||
List<MailAddress> ccRecipientList = new();
|
||||
foreach (string email in tecnNotificationUserEmails) {
|
||||
ccRecipientList.Add(new MailAddress(email));
|
||||
@ -59,10 +67,10 @@ public class ExpiringTECNWorker : IJob {
|
||||
StringBuilder bodyBuilder = new();
|
||||
bodyBuilder.Append($"Good day, TECN# {eCN.ECNNumber} will be expire on ");
|
||||
bodyBuilder.Append($"{eCN.ExpirationDate.ToString("MMMM dd, yyyy")}. ");
|
||||
bodyBuilder.Append($"<br /> Review TECN <a href='https://mesaapproval.mes.com/ECN/Edit?IssueID={eCN.ECNNumber}'> ");
|
||||
bodyBuilder.Append($"<br /> Review TECN <a href='{_baseUrl}/ECN/Edit?IssueID={eCN.ECNNumber}'> ");
|
||||
bodyBuilder.Append("here </a>");
|
||||
|
||||
string subject = $"Notice of expiring TECN - {eCN.Title}";
|
||||
string subject = $"Notice of Expiring TECN - {eCN.Title}";
|
||||
|
||||
await _smtpService.SendEmail(recipientList, ccRecipientList, subject, bodyBuilder.ToString());
|
||||
}
|
||||
@ -75,12 +83,12 @@ public class ExpiringTECNWorker : IJob {
|
||||
} finally {
|
||||
DateTime end = DateTime.Now;
|
||||
double latencyInMS = (end - start).TotalMilliseconds;
|
||||
_monInClient.PostAverage(metricName + "Latency", latencyInMS);
|
||||
_monInClient.PostMetric(metricName + "Latency", latencyInMS);
|
||||
|
||||
if (isInternalError) {
|
||||
_monInClient.PostStatus(metricName, StatusValue.Critical);
|
||||
_monInClient.PostStatus(metricName, State.Critical);
|
||||
} else {
|
||||
_monInClient.PostStatus(metricName, StatusValue.Ok);
|
||||
_monInClient.PostStatus(metricName, State.Ok);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user