public async Task Execute(IEnumerable <FundingDto> fundingDtos, IFundingServiceContext fundingServiceContext, CancellationToken cancellationToken) { _logger.LogDebug($"Starting {_taskName} Task"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List <Task <TOut> > taskList = new List <Task <TOut> >(); foreach (FundingDto fundingDto in fundingDtos) { taskList.Add(Process(fundingDto, cancellationToken)); } await Task.WhenAll(taskList).ConfigureAwait(false); IEnumerable <TOut> results = taskList.Select(t => t.Result) ?? Enumerable.Empty <TOut>(); var output = _fundingOutputCondenserService.Condense(results, fundingServiceContext.Ukprn, fundingServiceContext.Year); fundingServiceContext.FundingOutputKeys.TryGetValue(_outputKey, out var outputFileName); await _filePersistanceService.PersistAsync(outputFileName, fundingServiceContext.Container, output, cancellationToken).ConfigureAwait(false); _logger.LogDebug($"Persisted {_taskName} results - {stopWatch.ElapsedMilliseconds}"); }
public async Task Execute(IEnumerable <FundingDto> fundingDtos, IFundingServiceContext fundingServiceContext, CancellationToken cancellationToken) { _logger.LogDebug($"Starting {_taskName} Task"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); var output = _fundingOutputCondenserService.Condense(Enumerable.Empty <TOut>(), fundingServiceContext.Ukprn, fundingServiceContext.Year); fundingServiceContext.FundingOutputKeys.TryGetValue(_outputKey, out var outputFileName); await _filePersistanceService.PersistAsync(outputFileName, fundingServiceContext.Container, output, cancellationToken).ConfigureAwait(false); _logger.LogDebug($"Persisted {_taskName} results - {stopWatch.ElapsedMilliseconds}"); }
public async Task Execute(IEnumerable <FundingDto> fundingActorDtos, IFundingServiceContext fundingServiceContext, CancellationToken cancellationToken) { _logger.LogDebug($"Starting {_actorName} Actors"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List <Task <string> > taskList = new List <Task <string> >(); List <IFM70Actor> actors = new List <IFM70Actor>(); foreach (FundingDto fundingActorDto in fundingActorDtos) { IFM70Actor actor = _fundingActorProvider.Provide(); actors.Add(actor); taskList.Add(actor.Process(fundingActorDto, cancellationToken)); } await Task.WhenAll(taskList).ConfigureAwait(false); IEnumerable <FM70Global> results = taskList.Select(t => _jsonSerializationService.Deserialize <FM70Global>(t.Result)); _logger.LogDebug($"Completed {taskList.Count} {_actorName} Actors - {stopWatch.ElapsedMilliseconds}"); List <Task> tasksDestroy = new List <Task>(); foreach (IFM70Actor actor in actors) { tasksDestroy.Add(_fundingActorProvider.DestroyAsync(actor, cancellationToken)); } await Task.WhenAll(tasksDestroy).ConfigureAwait(false); _logger.LogDebug($"Destroyed {taskList.Count} {_actorName} Actors - {stopWatch.ElapsedMilliseconds}"); stopWatch.Restart(); var output = _fundingOutputCondenserService.Condense(results, fundingServiceContext.Ukprn, fundingServiceContext.Year); await _filePersistanceService.PersistAsync(fundingServiceContext.FundingFm70OutputKey, fundingServiceContext.Container, output, cancellationToken).ConfigureAwait(false); _logger.LogDebug($"Persisted {_actorName} results - {stopWatch.ElapsedMilliseconds}"); }