public async Task RunNotCompletedEdcEventsHandlerAsync([TimerTrigger("%Jobs:HandleNotCompletedEdcEvents:Schedule%")] TimerInfo timer) { await FunctionTemplate("HandleNotCompletedEdcEvents", async() => { var tillDate = DateTime.UtcNow.AddMinutes(-_edcConfiguration.MessageTimeToLiveInMinutes); var notCompletedEventLogs = await _eventLogService.GetAsync(log => log.StateId != (int)EventStateEnum.Completed && log.CreationTime < tillDate); foreach (var eventLog in notCompletedEventLogs) { _logger.Event($"{_jobsConfiguration.LogEventId}.HandleNotCompletedEdcEvents").With .Message($"Event Failed: EventId:{eventLog.EventId}, EventName: {eventLog.EventTypeName}, EventContent: { JsonConvert.SerializeObject(eventLog.Content)}") .AsError(); if (eventLog.TimesSent >= _jobsConfiguration.HandleNotCompletedEdcEvents.MaxAttemptsCountBeforeEmailSending) { var baseEmailTemplate = _emailTemplateProvider.GetBaseTemplateHtml(); var serviceBusErrorEmailTemplate = _emailTemplateProvider.GetTemplateHtml( _jobsConfiguration.HandleNotCompletedEdcEvents.ServiceBusErrorEmailTemplateName); await _emailService.SendNotificationAsync(new ServiceBusErrorEmailNotification( new ServiceBusErrorEmailNotificationTemplateModel(eventLog.EventId), baseEmailTemplate, serviceBusErrorEmailTemplate, new RecipientDto(_jobsConfiguration.HandleNotCompletedEdcEvents.ServiceBusErrorEmailRecipients, null))); } eventLog.StateId = (int)EventStateEnum.PublishedFailed; await _eventLogService.UpdateAsync(eventLog); await _edcPublishService.RepublishAsync(eventLog.EventId); } }); }