コード例 #1
0
        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);
                }
            });
        }
コード例 #2
0
        public async Task RepublishAsync(Guid eventId, int?delayInSeconds = null)
        {
            var eventLog = await _eventLogService.GetAsync(eventId);

            if (eventLog.StateId != (int)EventStateEnum.Completed)
            {
                await _eventBusPublisher.PublishToTopicAsync(eventLog.Content, delayInSeconds);

                await _eventLogService.MarkAsPublishedAsync(eventLog.Content);
            }
        }