protected virtual async Task <Initiative> OnWorkOrderUpdatedAsync(WorkOrderUpdatedEventArgs args, CancellationToken token) { if (args == null) { throw new ArgumentNullException("args"); } if (string.IsNullOrWhiteSpace(args.WorkOrderId)) { throw new ArgumentException("WorkOrderId cannot be empty"); } if (string.IsNullOrWhiteSpace(args.UpdatedStatus)) { throw new ArgumentException("UpdatedStatus cannot be empty"); } using (LogContext.PushProperty("WorkOrderId", args.WorkOrderId)) { Initiative idea = await GetInitiativeByWorkOrderId(args.WorkOrderId); if (idea == null) { _logger.Warning("Remedy message received for WorkItemId {WorkOrderId} but could not find an associated initiative", args.WorkOrderId); } else { using (LogContext.PushProperty("InitiativeId", idea.Id)) { var workOrderStatus = Enum.Parse <InitiativeStatus>(args.UpdatedStatus); bool anyChange = await UpdateIdeaAssignee(idea, args.AssigneeEmail, args.AssigneeDisplayName); anyChange = UpdateIdeaWithNewWorkOrderStatus(idea, workOrderStatus, args.UpdatedDateUtc, args.EtaUtc) || anyChange; if (anyChange) { await _ideaRepository.UpdateInitiativeAsync(idea); } } } return(idea); } }
public Task SendWorkOrderUpdatedAsync(WorkOrderUpdatedEventArgs args) { // do nothing return(Task.CompletedTask); }
protected virtual async Task <WorkOrderUpdatedEventArgs> TryProcessWorkItemChanged( OutputMapping1GetListValues workItem) { // we need to convert the Assignee 3+3 to an email so Octava can use it // from manual inspection in looks like this field is the "assignee 3+3": string assignee3and3 = workItem.ASLOGID; PersonData assignee = null; if (string.IsNullOrWhiteSpace(assignee3and3)) { _logger.Information("Assignee is empty"); } else { _logger.Information("Looking up assignee with 3+3 {User3and3}", assignee3and3); try { assignee = await _peopleService.GetPersonAsync(assignee3and3); } catch (Exception err) { _logger.Warning(err, "Unable to get email for Remedy Work Order Assignee {User3and3}: {ErrorMessage}", assignee3and3, err.Message); } } InitiativeStatus?newInitiativeStatus = GetInitiativeStatusForRemedyStatus(workItem.Status); if (newInitiativeStatus == null) { _logger.Information("Abondining updated work item because an appropriate InitiativeStatus could not be determined from the Remedy Status {WorkItemStatus}", workItem.Status); return(null); } DateTime?etaUtc = null; try { etaUtc = await _initiativeStatusEtaService.GetStatusEtaFromNowUtcAsync(newInitiativeStatus.Value); } catch (Exception err) { _logger.Warning(err, "Unable to get an updated ETA for initiative status {InitiativeStatus}: {ErrorMessage}", newInitiativeStatus.Value, err.Message); } try { // Note the ToUniversalTime on the Last_Modified_Date: // this works because this service runs in the same time zone as Remedy. var args = new WorkOrderUpdatedEventArgs() { WorkOrderId = workItem.InstanceId, UpdatedDateUtc = workItem.Last_Modified_Date.ToUniversalTime(), RemedyStatus = workItem.Status.ToString(), UpdatedStatus = newInitiativeStatus.Value.ToString(), AssigneeEmail = assignee?.Email, AssigneeDisplayName = assignee?.DisplayName, EtaUtc = etaUtc }; await _initiativeMessageSender.SendWorkOrderUpdatedAsync(args); return(args); } catch (Exception e) { Guid correlationId = Guid.NewGuid(); _logger.Error(e, $"Unable to process work item changed (correlationId {correlationId}): {e.Message}"); _logger.Debug($"Work item change that caused processing error (correlationId {correlationId}): { workItem }"); throw; } }