public override async Task Process(Message message) { Guard.ArgumentNotNull(message, nameof(message)); Reference author = message.GetUserDetails(); string specificationId = message.UserProperties["specification-id"] as string; bool publishAll = false; if (message.UserProperties.ContainsKey("publish-all")) { publishAll = bool.Parse(message.UserProperties["publish-all"].ToString()); } IEnumerable <string> batchProviders = null; if (message.UserProperties.ContainsKey("providers-batch")) { batchProviders = JsonExtensions.AsPoco <IEnumerable <string> >(message.UserProperties["providers-batch"].ToString()); } SpecificationSummary specification = await _specificationService.GetSpecificationSummaryById(specificationId); if (specification == null) { throw new NonRetriableException($"Could not find specification with id '{specificationId}'"); } foreach (Reference fundingStream in specification.FundingStreams) { (IDictionary <string, PublishedProvider> publishedProvidersForFundingStream, IDictionary <string, PublishedProvider> scopedPublishedProviders) = await _providerService.GetPublishedProviders(fundingStream, specification); IDictionary <string, PublishedProvider> publishedProvidersByPublishedProviderId = publishedProvidersForFundingStream.Values.ToDictionary(_ => _.PublishedProviderId); IEnumerable <PublishedProvider> selectedPublishedProviders = batchProviders.IsNullOrEmpty() ? publishedProvidersForFundingStream.Values : batchProviders.Where(_ => publishedProvidersByPublishedProviderId.ContainsKey(_)).Select(_ => publishedProvidersByPublishedProviderId[_]); TemplateMapping templateMapping = await GetTemplateMapping(fundingStream, specification.Id); IEnumerable <PublishedFundingVersion> publishedFundingVersions = publishAll ? await _publishedFundingVersionDataService.GetPublishedFundingVersion(fundingStream.Id, specification.FundingPeriod.Id) : (await _publishingResiliencePolicy.ExecuteAsync(() => _publishedFundingDataService.GetCurrentPublishedFunding(fundingStream.Id, specification.FundingPeriod.Id))).Select(_ => _.Current); TemplateMetadataContents templateMetadataContents = await _policiesService.GetTemplateMetadataContents(fundingStream.Id, specification.FundingPeriod.Id, specification.TemplateIds[fundingStream.Id]); if (templateMetadataContents == null) { throw new NonRetriableException($"Unable to get template metadata contents for funding stream. '{fundingStream.Id}'"); } // Save contents to blob storage and search for the feed _logger.Information($"Saving published funding contents"); await _publishedFundingContentsPersistanceService.SavePublishedFundingContents(publishedFundingVersions, templateMetadataContents); _logger.Information($"Finished saving published funding contents"); // Generate contents JSON for provider and save to blob storage IPublishedProviderContentsGenerator generator = _publishedProviderContentsGeneratorResolver.GetService(templateMetadataContents.SchemaVersion); await _publishedProviderContentsPersistanceService.SavePublishedProviderContents(templateMetadataContents, templateMapping, selectedPublishedProviders, generator, publishAll); } }