public async Task SavePublishedFundingContents(IEnumerable <PublishedFundingVersion> publishedFundingToSave, TemplateMetadataContents templateMetadataContents)
        {
            IPublishedFundingContentsGenerator generator = _publishedFundingContentsGeneratorResolver.GetService(templateMetadataContents.SchemaVersion);

            List <Task>   allTasks  = new List <Task>();
            SemaphoreSlim throttler = new SemaphoreSlim(initialCount: _publishingEngineOptions.SavePublishedFundingContentsConcurrencyCount);

            foreach (PublishedFundingVersion publishedFundingVersion in publishedFundingToSave)
            {
                await throttler.WaitAsync();

                allTasks.Add(
                    Task.Run(async() =>
                {
                    try
                    {
                        string contents = generator.GenerateContents(publishedFundingVersion, templateMetadataContents);

                        if (string.IsNullOrWhiteSpace(contents))
                        {
                            throw new RetriableException($"Generator failed to generate content for published provider version with id: '{publishedFundingVersion.Id}'");
                        }

                        string blobName = GetBlobName(publishedFundingVersion);
                        await _publishedFundingRepositoryPolicy.ExecuteAsync(() =>
                                                                             UploadBlob(GetBlobName(publishedFundingVersion), contents, GetMetadata(publishedFundingVersion)));
                    }
                    finally
                    {
                        throttler.Release();
                    }
                }));
            }
            await TaskHelper.WhenAllAndThrow(allTasks.ToArray());
        }
Beispiel #2
0
        public void SetUp()
        {
            IPublishedFundingContentsGeneratorResolver publishedFundingContentsGeneratorResolver = Substitute.For <IPublishedFundingContentsGeneratorResolver>();
            IConfiguration configuration = Substitute.For <IConfiguration>();

            _blobClient = Substitute.For <IBlobClient>();
            _publishedFundingContentsGenerator = Substitute.For <IPublishedFundingContentsGenerator>();
            _templateMetadataContents          = new Common.TemplateMetadata.Models.TemplateMetadataContents {
                SchemaVersion = _schema
            };

            publishedFundingContentsGeneratorResolver.GetService(Arg.Is(_schema))
            .Returns(_publishedFundingContentsGenerator);

            _publishedFundingContentsPersistanceService = new PublishedFundingContentsPersistanceService(
                publishedFundingContentsGeneratorResolver,
                _blobClient, PublishingResilienceTestHelper.GenerateTestPolicies(),
                new PublishingEngineOptions(configuration));

            _cloudBlob = Substitute.For <ICloudBlob>();

            _publishedFundingPeriod = new PublishedFundingPeriod {
                Type = PublishedFundingPeriodType.AY, Period = "123"
            };
        }
Beispiel #3
0
        public void Register(string schemaVersion,
                             IPublishedFundingContentsGenerator publishedFundingContentsGenerator)
        {
            Guard.IsNullOrWhiteSpace(schemaVersion, nameof(schemaVersion));
            Guard.ArgumentNotNull(publishedFundingContentsGenerator, nameof(publishedFundingContentsGenerator));

            _supportedVersions.TryAdd(schemaVersion, publishedFundingContentsGenerator);
        }
Beispiel #4
0
        public ProviderDocumentGenerator(IPublishedProviderContentsGenerator publishedProviderContentsGenerator, IPublishedFundingContentsGenerator publishedFundingContentsGenerator,
                                         IProvidersApiClient providersApiClient, IOrganisationGroupResiliencePolicies organisationGroupResiliencePolicies, ILogger logger)
        {
            _publishedProviderContentsGenerator = publishedProviderContentsGenerator;
            _publishedFundingContentsGenerator  = publishedFundingContentsGenerator;
            _logger = logger;

            organisationGroupTargetProviderLookup = new OrganisationGroupTargetProviderLookup(providersApiClient, organisationGroupResiliencePolicies);
        }
Beispiel #5
0
        public void RegistersGeneratorsByTheSuppliedSchemaVersions()
        {
            string versionOne   = NewRandomString();
            string versionTwo   = NewRandomString();
            string versionThree = NewRandomString();
            IPublishedFundingContentsGenerator generatorOne   = NewGenerator();
            IPublishedFundingContentsGenerator generatorTwo   = NewGenerator();
            IPublishedFundingContentsGenerator generatorThree = NewGenerator();

            GivenTheGenerators((versionOne, generatorOne),
                               (versionTwo, generatorTwo),
                               (versionThree, generatorThree));

            IPublishedFundingContentsGenerator resolvedGenerator = WhenTheGeneratorIsResolved(versionTwo);

            resolvedGenerator
            .Should()
            .BeSameAs(generatorTwo);
        }
Beispiel #6
0
 public bool TryGetService(string schemaVersion,
                           out IPublishedFundingContentsGenerator publishedFundingContentsGenerator)
 => _supportedVersions.TryGetValue(schemaVersion, out publishedFundingContentsGenerator);