public static async Task RunAsync(RunMode mode, string basePath) { var container = ConfigureContainer(mode, basePath); ConfigureLog.ConfigureNLogWithAppInsightsTarget(container.Resolve <IConfigConfigurationProvider>()); var processEmailNotificationsService = container.Resolve <IProcessEmailNotifications>(); await processEmailNotificationsService.ProcessEmailNotificationsAsync(); }
private static async Task GetAVForSocMappingFunc(SocMapping myQueueItem, IAsyncCollector <ProjectedVacancySummary> projectedVacancySummary, IAsyncCollector <AuditRecord <object, object> > auditRecord, IAsyncCollector <SocMapping> invalidSocMappings, TraceWriter log, int attempt = 1) { try { var startTime = DateTime.UtcNow; ConfigureLog.ConfigureNLogWithAppInsightsTarget(); var mappedResult = await Startup.RunAsync(myQueueItem, RunMode.Azure, auditRecord, new AuditRecord <object, object> { CorrelationId = myQueueItem.CorrelationId, StartedAt = startTime, EndedAt = DateTime.Now, Function = nameof(GetAVForSocMappingAzFunction), Input = "", Output = "" }).ConfigureAwait(false); await AuditMapping(myQueueItem, auditRecord, startTime, mappedResult); var projectedResult = Function.ProjectVacanciesForSoc.Startup.Run(RunMode.Azure, mappedResult); projectedResult.CorrelationId = myQueueItem.CorrelationId; await projectedVacancySummary.AddAsync(projectedResult).ConfigureAwait(false); await AuditProjections(myQueueItem, auditRecord, startTime, mappedResult, projectedResult); } catch (AvApiResponseException responseException) { if (responseException.StatusCode == HttpStatusCode.BadRequest) { await invalidSocMappings.AddAsync(myQueueItem); log.Warning($"Exception raised while fetching AV for SOC {myQueueItem.SocCode} API -Url:{responseException.Message} with ErrorCode :{responseException.StatusCode}"); } else if (responseException.StatusCode == ((HttpStatusCode)429) && attempt < 3) { log.Info($"Got API request limit error for SOC {myQueueItem.SocCode} - will wait for 60 seconds"); var retryInSeconds = 60; int.TryParse(Regex.Match(responseException.Message, "\\d+")?.Value, out retryInSeconds); await Task.Delay(retryInSeconds * 1000); await GetAVForSocMappingFunc(myQueueItem, projectedVacancySummary, auditRecord, invalidSocMappings, log, attempt ++); } else { throw; } } finally { log.Info($"C# Queue trigger function processed: {myQueueItem}"); } }
private static async Task GetDetailsForProjectedAvFunc(ProjectedVacancySummary myQueueItem, IAsyncCollector <ProjectedVacancyDetails> projectedVacancyDetails, IAsyncCollector <AuditRecord <object, object> > auditRecord, int attempt = 1) { try { var startTime = DateTime.UtcNow; ConfigureLog.ConfigureNLogWithAppInsightsTarget(); var getDetailsResult = await Startup.RunAsync(myQueueItem, RunMode.Azure, auditRecord, new AuditRecord <object, object> { CorrelationId = myQueueItem.CorrelationId, StartedAt = startTime, EndedAt = DateTime.Now, Function = nameof(GetAVDetailsForProjectedAVFunction), Input = "", Output = "" }).ConfigureAwait(false); getDetailsResult.CorrelationId = myQueueItem.CorrelationId; await AuditMapping(myQueueItem, auditRecord, startTime, getDetailsResult); await projectedVacancyDetails.AddAsync(getDetailsResult).ConfigureAwait(false); } catch (AvApiResponseException responseException) { if (responseException.StatusCode == ((HttpStatusCode)429) && attempt < 3) { var retryInSeconds = 60; int.TryParse(Regex.Match(responseException.Message, "\\d+")?.Value, out retryInSeconds); await Task.Delay(retryInSeconds * 1000); await GetDetailsForProjectedAvFunc(myQueueItem, projectedVacancyDetails, auditRecord, attempt ++); } else { throw; } } }