예제 #1
0
        // ReSharper disable once UnusedMember.Global
        public async Task PublishReleaseContent(
            [QueueTrigger(PublishReleaseContentQueue)]
            PublishReleaseContentMessage message,
            ExecutionContext executionContext,
            ILogger logger)
        {
            logger.LogInformation($"{executionContext.FunctionName} triggered at: {DateTime.Now}");

            await UpdateStage(message.ReleaseId, message.ReleaseStatusId, State.Started);

            var context = new PublishContext(DateTime.UtcNow, false);

            try
            {
                await _contentService.UpdateContent(context, message.ReleaseId);

                await _releaseService.SetPublishedDatesAsync(message.ReleaseId, context.Published);

                if (!PublisherUtils.IsDevelopment())
                {
                    await _releaseService.DeletePreviousVersionsStatisticalData(message.ReleaseId);
                }

                await _contentService.DeletePreviousVersionsDownloadFiles(message.ReleaseId);

                await _contentService.DeletePreviousVersionsContent(message.ReleaseId);

                await _notificationsService.NotifySubscribers(message.ReleaseId);
                await UpdateStage(message.ReleaseId, message.ReleaseStatusId, State.Complete);
            }
            catch (Exception e)
            {
                logger.LogError(e, $"Exception occured while executing {executionContext.FunctionName}");
                logger.LogError(e.StackTrace);

                await UpdateStage(message.ReleaseId, message.ReleaseStatusId, State.Failed,
                                  new ReleaseStatusLogMessage($"Exception publishing release immediately: {e.Message}"));
            }

            logger.LogInformation($"{executionContext.FunctionName} completed");
        }
예제 #2
0
        public async Task PublishReleaseContent(
            [QueueTrigger(PublishReleaseContentQueue)]
            PublishReleaseContentMessage message,
            ExecutionContext executionContext,
            ILogger logger)
        {
            logger.LogInformation("{0} triggered at: {1}",
                                  executionContext.FunctionName,
                                  DateTime.UtcNow);

            await UpdateStage(message.ReleaseId, message.ReleaseStatusId, State.Started);

            var context = new PublishContext(DateTime.UtcNow, false);

            try
            {
                await _contentService.UpdateContent(context, message.ReleaseId);

                await _releaseService.SetPublishedDates(message.ReleaseId, context.Published);

                if (!EnvironmentUtils.IsLocalEnvironment())
                {
                    await _releaseService.DeletePreviousVersionsStatisticalData(message.ReleaseId);
                }

                // Invalidate the cached trees in case any methodologies/publications
                // are now accessible for the first time after publishing these releases
                await _blobCacheService.DeleteItem(new AllMethodologiesCacheKey());

                await _blobCacheService.DeleteItem(new PublicationTreeCacheKey());

                await _blobCacheService.DeleteItem(new PublicationTreeCacheKey(PublicationTreeFilter.AnyData));

                await _blobCacheService.DeleteItem(new PublicationTreeCacheKey(PublicationTreeFilter.LatestData));

                var release = await _contentDbContext.Releases
                              .Include(r => r.Publication)
                              .Where(r => r.Id == message.ReleaseId)
                              .SingleAsync();

                await _blobCacheService.DeleteItem(new PublicationCacheKey(release.Publication.Slug));

                // TODO: @MarkFix EES-3149 Delete superseded publication's cache here too?

                await _contentService.DeletePreviousVersionsDownloadFiles(message.ReleaseId);

                await _contentService.DeletePreviousVersionsContent(message.ReleaseId);

                await _notificationsService.NotifySubscribersIfApplicable(message.ReleaseId);

                await UpdateStage(message.ReleaseId, message.ReleaseStatusId, State.Complete);
            }
            catch (Exception e)
            {
                logger.LogError(e, "Exception occured while executing {0}",
                                executionContext.FunctionName);
                logger.LogError("{StackTrace}", e.StackTrace);

                await UpdateStage(message.ReleaseId, message.ReleaseStatusId, State.Failed,
                                  new ReleasePublishingStatusLogMessage($"Exception publishing release immediately: {e.Message}"));
            }

            logger.LogInformation("{0} completed", executionContext.FunctionName);
        }