// ReSharper disable once UnusedMember.Global public async Task PublishStagedReleaseContent([TimerTrigger("%PublishReleaseContentCronSchedule%")] TimerInfo timer, ExecutionContext executionContext, ILogger logger) { logger.LogInformation($"{executionContext.FunctionName} triggered at: {DateTime.Now}"); var scheduled = (await QueryScheduledReleases()).ToList(); if (scheduled.Any()) { var published = new List <ReleaseStatus>(); foreach (var releaseStatus in scheduled) { logger.LogInformation($"Moving content for release: {releaseStatus.ReleaseId}"); await UpdateStage(releaseStatus, Started); try { await _publishingService.PublishStagedReleaseContentAsync(releaseStatus.ReleaseId); published.Add(releaseStatus); } catch (Exception e) { logger.LogError(e, $"Exception occured while executing {executionContext.FunctionName}"); await UpdateStage(releaseStatus, Failed, new ReleaseStatusLogMessage($"Exception in publishing stage: {e.Message}")); } } var releaseIds = published.Select(status => status.ReleaseId).ToArray(); try { if (!PublisherUtils.IsDevelopment()) { await _releaseService.DeletePreviousVersionsStatisticalData(releaseIds); } await _contentService.DeletePreviousVersionsDownloadFiles(releaseIds); await _contentService.DeletePreviousVersionsContent(releaseIds); await _notificationsService.NotifySubscribers(releaseIds); await UpdateStage(published, Complete); } catch (Exception e) { logger.LogError(e, $"Exception occured while executing {executionContext.FunctionName}"); await UpdateStage(published, Failed, new ReleaseStatusLogMessage($"Exception in publishing stage: {e.Message}")); } } logger.LogInformation( $"{executionContext.FunctionName} completed. {timer.FormatNextOccurrences(1)}"); }
// 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"); }
public async Task PublishStagedReleaseContent([TimerTrigger("%PublishReleaseContentCronSchedule%")] TimerInfo timer, ExecutionContext executionContext, ILogger logger) { logger.LogInformation("{0} triggered at: {1}", executionContext.FunctionName, DateTime.UtcNow); var scheduled = (await QueryScheduledReleases()).ToList(); if (scheduled.Any()) { var published = new List <ReleasePublishingStatus>(); foreach (var releaseStatus in scheduled) { logger.LogInformation("Moving content for release: {0}", releaseStatus.ReleaseId); await UpdateStage(releaseStatus, Started); try { await _publishingService.PublishStagedReleaseContent(releaseStatus.ReleaseId, releaseStatus.PublicationSlug); published.Add(releaseStatus); } catch (Exception e) { logger.LogError(e, "Exception occured while executing {0}", executionContext.FunctionName); await UpdateStage(releaseStatus, Failed, new ReleasePublishingStatusLogMessage($"Exception in publishing stage: {e.Message}")); } } var releaseIds = published.Select(status => status.ReleaseId).ToArray(); try { if (!EnvironmentUtils.IsLocalEnvironment()) { await _releaseService.DeletePreviousVersionsStatisticalData(releaseIds); } // Invalidate the cached trees in case any methodologies/publications // are now accessible for the first time after publishing these releases await _contentService.DeleteCachedTaxonomyBlobs(); await _contentService.DeletePreviousVersionsDownloadFiles(releaseIds); await _contentService.DeletePreviousVersionsContent(releaseIds); await _notificationsService.NotifySubscribersIfApplicable(releaseIds); await UpdateStage(published, Complete); } catch (Exception e) { logger.LogError(e, "Exception occured while executing {0}", executionContext.FunctionName); await UpdateStage(published, Failed, new ReleasePublishingStatusLogMessage($"Exception in publishing stage: {e.Message}")); } } logger.LogInformation( "{0} completed. {1}", executionContext.FunctionName, timer.FormatNextOccurrences(1)); }
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); }