Exemplo n.º 1
0
        protected override async Task <bool> OnMessageReceivedAsync(DocumentPublishCancelEventMessage message,
                                                                    CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            try
            {
                var publishDocumentTask = await PublishDocumentTaskRepository.GetAsync(message.Id);

                if (publishDocumentTask == null)
                {
                    return(false);
                }

                if (publishDocumentTask.IsFinished)
                {
                    return(true);
                }

                SavePublishTaskInfo(publishDocumentTask);
                await NotifyService.SendNotificationAsync(publishDocumentTask);

                return(true);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Возникла ошибка при обработке сообщения");
                return(false);
            }
        }
Exemplo n.º 2
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);
            }
        }