Last active
October 19, 2018 19:16
-
-
Save vmandic/1f3fc06d5f96185ee147769fabb33d13 to your computer and use it in GitHub Desktop.
meds-processor, p2, s5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<ISet<HzzoMedsDownloadDto>> Run(ISet<HzzoMedsDownloadDto> meds) | |
{ | |
// NOTE: throttle requests in parallel | |
var parallelismDegree = 5; | |
var waitBetweenRequestsMs = 500; | |
var savingItems = new List<Task>(); | |
var notDownloadedDocs = meds.Where(x => !x.IsAlreadyDownloaded).ToList(); | |
for (int i = 0; i < notDownloadedDocs.Count; i += parallelismDegree) | |
{ | |
var queuedMeds = meds.Skip(i).Take(parallelismDegree); | |
savingItems.AddRange( | |
(await Task.WhenAll(queuedMeds.Select(DownloadExcel))) | |
.Select(SaveExcel)); | |
await Task.Delay(waitBetweenRequestsMs); | |
} | |
Task.WaitAll(savingItems.ToArray()); | |
return meds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment