public void Run() { var sb = new StringBuilder("The following actions were taken to resolve issues with traineeship applications:"); sb.AppendLine(); var applicationsToCheck = _applicationDiagnosticsRepository.GetSubmittedApplicationsWithUnsetLegacyId().ToList(); foreach (var application in applicationsToCheck) { var applicationStatusSummaries = _legacyApplicationStatusesProvider.GetCandidateApplicationStatuses(application.Candidate); var applicationDetail = application.TraineeshipApplicationDetail; var applicationStatusSummary = applicationStatusSummaries.SingleOrDefault(s => s.LegacyVacancyId == applicationDetail.Vacancy.Id); if (applicationStatusSummary == null) { var message = new SubmitTraineeshipApplicationRequest { ApplicationId = applicationDetail.EntityId }; _messageBus.PublishMessage(message); _logger.Warn("Could not patch traineeship application id: {0} with legacy id as no matching application status summary was found. Re-queued instead", applicationDetail.EntityId); } else { _applicationDiagnosticsRepository.UpdateLegacyApplicationId(applicationDetail, applicationStatusSummary.LegacyApplicationId); _logger.Info("Patching traineeship application id: {0} with legacy id: {1}", applicationDetail.EntityId, applicationStatusSummary.LegacyApplicationId); } } }
public void Run() { var sb = new StringBuilder("The following actions were taken to resolve issues with traineeship applications:"); sb.AppendLine(); var applicationsToRequeue = _applicationDiagnosticsRepository.GetApplicationsForValidCandidatesWithUnsetLegacyId().ToList(); foreach (var application in applicationsToRequeue) { _logger.Info("Re-queuing create traineeship application message for application id: {0}", application.EntityId); var message = new SubmitTraineeshipApplicationRequest { ApplicationId = application.EntityId }; _messageBus.PublishMessage(message); var requeuedMessage = string.Format("Re-queued create traineeship application message for candidate id: {0}", application.EntityId); _logger.Info(requeuedMessage); sb.AppendLine(requeuedMessage); } if (!applicationsToRequeue.Any()) { return; } //Wait 5 seconds to allow messages to be processed. Nondeterministic of course Thread.Sleep(TimeSpan.FromSeconds(5)); var applicationsForValidCandidatesWithUnsetLegacyId = _applicationDiagnosticsRepository.GetApplicationsForValidCandidatesWithUnsetLegacyId().ToList(); if (applicationsForValidCandidatesWithUnsetLegacyId.Any()) { sb.AppendLine("The actions taken did not resolve the following issues with traineeship applications:"); applicationsForValidCandidatesWithUnsetLegacyId.ForEach(a => sb.AppendLine(string.Format("Application with id: {0} is associated with a valid candidate but has an unset legacy application id", a.EntityId))); _logger.Error(sb.ToString()); } else { sb.AppendLine("The actions taken appear to have resolved the issues"); _logger.Warn(sb.ToString()); } }
private void PublishMessage(TraineeshipApplicationDetail traineeshipApplicationDetail) { try { var message = new SubmitTraineeshipApplicationRequest { ApplicationId = traineeshipApplicationDetail.EntityId }; _messageBus.PublishMessage(message); } catch { // Compensate for failure to enqueue application submission by deleting the application. _traineeshipApplicationWriteRepository.Delete(traineeshipApplicationDetail.EntityId); throw; } }