I have a sequence, retrieve data from a vendor API, cleanup our stage tables, and write the retrieve data into the database. What I have:
public static async Task Main()
{
try
{
IDataRetrievalService api = services.GetService<IDataRetrievalService>();
AuthenticationModel authenticated = await api.GetToken();
authenticated.Decorate(Log.Logger);
#region Web Request:
var budget = api.GetBudgetReport(authenticated);
var site = api.GetSiteReport(authenticated);
var project = api.GetProjectReport(authenticated);
var task = api.GetTaskReport(authenticated);
var workEffort = api.GetWorkEffortReport(authenticated);
var invoiceMaterial = api.GetInvoiceMaterialReport(authenticated);
var pickup = api .GetPickupSummary(authenticated);
var pickupMaterial = api.GetPickupMaterialReport(authenticated);
var dropship = api.GetDropshipReport(authenticated);
var dropshipMaterial = api.GetDropshipMaterialReport(authenticated);
var materialType = api.GetMaterialTypeReport(authenticated);
#endregion
IDatabaseCleanupService cleanup = services.GetService<IDatabaseCleanupService>();
await Task.WhenAll(
budget,
cleanup.PurgeBudget(),
site,
cleanup.PurgeSite(),
project,
cleanup.PurgeProject(),
task,
cleanup.PurgeTask(),
workEffort,
cleanup.PurgeWorkEffort(),
invoiceMaterial,
cleanup.PurgeInvoiceMaterial(),
pickup,
cleanup.PurgePickupSummary(),
pickupMaterial,
cleanup.PurgePickupMaterial(),
dropship,
cleanup.PurgeDropship(),
dropshipMaterial,
cleanup.PurgeDropshipMaterial(),
materialType,
cleanup.PurgeMaterialType()
);
IDatabaseImporterService importer = services.GetService<IDatabaseImporterService>();
await Task.WhenAll(
importer.InsertBudget(await budget),
importer.InsertSite(await site),
importer.InsertProject(await project),
importer.InsertTask(await task),
importer.InsertWorkEffort(await workEffort),
importer.InsertInvoiceMaterial(await invoiceMaterial),
importer.InsertPickupSummary(await pickup),
importer.InsertPickupMaterial(await pickupMaterial),
importer.InsertDropship(await dropship),
importer.InsertDropshipMaterial(await dropshipMaterial),
importer.InsertMaterialType(await materialType)
);
}
catch (Exception exception)
{
exception.Decorate(Log.Logger);
throw;
}
}
I feel though that the second WhenAll should not need to wait for a batch of task that should of been completed above, the syntax feels weird to me.
cleanup.PurgeXYZ
andimporter.InsertXYZ
methods async? \$\endgroup\$WhenAll
is called those variables are in essence a completed task. \$\endgroup\$