Esempio n. 1
0
 private void SavePublishTaskInfo(PublishDocumentTask publishDocumentTask)
 {
     publishDocumentTask.State     = PublishState.Canceled;
     publishDocumentTask.UpdatedAt = DateTime.Now;
     _logger.LogDebug($"id={publishDocumentTask.DocumentId} PublishDocumentTask.State= {publishDocumentTask.State}");
     PublishDocumentTaskRepository.Save(publishDocumentTask);
 }
 private void SavePublishTaskInfo(PublishDocumentTask publishDocumentTask)
 {
     publishDocumentTask.IsDelivered = true;
     publishDocumentTask.UpdatedAt   = DateTime.Now;
     _logger.LogDebug($"Delivered task id={publishDocumentTask.DocumentId}");
     PublishDocumentTaskRepository.Save(publishDocumentTask);
 }
Esempio n. 3
0
        protected override async Task <bool> OnMessageReceivedAsync(DocumentPublishEventMessage message,
                                                                    CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            try
            {
                var publishDocumentTask = await PublishDocumentTaskRepository.GetAsync(message.Id);

                if (publishDocumentTask == null)
                {
                    publishDocumentTask = new PublishDocumentTask(message);
                    PublishDocumentTaskRepository.Save(publishDocumentTask);
                    await NotifyService.SendNotificationAsync(publishDocumentTask);
                }

                if (!CheckIsNeedToProcessMessage(publishDocumentTask))
                {
                    return(true);
                }

                var documentPublicationInfo = await ProcessMessage(message, cancellationToken);

                SavePublishTaskInfo(publishDocumentTask, documentPublicationInfo);

                await NotifyService.SendNotificationAsync(publishDocumentTask);

                if (documentPublicationInfo.ResultType == PublicationResultType.Processing)
                {
                    var updateMessage = CreatePublishUpdateMessage(message, documentPublicationInfo.RefId);
                    EventBus.PublishMessage(updateMessage);

                    return(false);
                }

                var documentPublishResultEventMessage = new DocumentPublishResultEventMessage
                {
                    UserId     = message.UserId,
                    Id         = message.Id,
                    CreatedAt  = message.CreatedAt,
                    LoadId     = documentPublicationInfo.LoadId,
                    ResultType = documentPublicationInfo.ResultType
                };

                EventBus.PublishMessage(documentPublishResultEventMessage);

                return(true);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Возникла ошибка при обработке сообщения");
                return(false);
            }
        }
Esempio n. 4
0
        private void SavePublishTaskInfo(PublishDocumentTask publishDocumentTask,
                                         DocumentPublicationInfo documentPublicationInfo)
        {
            var publishDocumentTaskAttempt = new PublishDocumentTaskAttempt
            {
                PublishDocumentTaskId = publishDocumentTask.Id,
                Response         = documentPublicationInfo.Response,
                Request          = documentPublicationInfo.Request,
                HasEisExceptions = documentPublicationInfo.HasInnerExceptions,
                Result           = documentPublicationInfo.ResultType
            };

            publishDocumentTask.State            = ConvertToPublishState(documentPublicationInfo.ResultType);
            publishDocumentTask.HasEisExceptions = publishDocumentTask.HasEisExceptions ||
                                                   publishDocumentTaskAttempt.HasEisExceptions;
            publishDocumentTask.LoadId    = documentPublicationInfo.LoadId;
            publishDocumentTask.RefId     = documentPublicationInfo.RefId;
            publishDocumentTask.UpdatedAt = DateTime.Now;
            publishDocumentTask.PublishDocumentTaskAttempts.Add(publishDocumentTaskAttempt);
            PublishDocumentTaskRepository.Save(publishDocumentTask);
            _logger.LogDebug(
                $"id={publishDocumentTask.DocumentId} PublishDocumentTask.State= {publishDocumentTask.State} attempt result= {publishDocumentTaskAttempt.Result}");

            PublishState ConvertToPublishState(PublicationResultType resultType)
            {
                switch (resultType)
                {
                case PublicationResultType.Success:
                    return(PublishState.Published);

                case PublicationResultType.Failed:
                    return(PublishState.Failed);

                case PublicationResultType.Processing:
                    return(PublishState.Processing);

                case PublicationResultType.XmlValidationError:
                    return(PublishState.XmlValidationError);

                default:
                    throw new ArgumentOutOfRangeException(nameof(resultType));
                }
            }
        }