in code/PublishToEmbeddedSocial/Components/PublishStops.cs [30:68]
public static async Task PublishStopsToEmbeddedSocial(StorageManager diffStorage, StorageManager diffMetadataStorage, StorageManager publishStorage, StorageManager publishMetadataStorage, EmbeddedSocial embeddedSocial, string runId)
{
// get all the diff metadata
IEnumerable<DiffMetadataEntity> diffMetadata = diffMetadataStorage.DiffMetadataStore.Get(runId);
// if there are no entries, then there is nothing to do
if (diffMetadata == null || diffMetadata.Count() < 1)
{
return;
}
// select the stop diff metadata entries
diffMetadata = from entity in diffMetadata
where entity.RecordType == RecordType.Stop.ToString()
select entity;
// if there are no entries, then there is nothing to do
if (diffMetadata == null || diffMetadata.Count() < 1)
{
return;
}
// each entry covers a region.
// process stops per region in parallel.
// it is ok to execute these in parallel because the operations being done are independent of each other.
List<Task> tasks = new List<Task>();
foreach (DiffMetadataEntity diffMetadataEntity in diffMetadata)
{
Task task = Task.Run(async () =>
{
string regionId = diffMetadataEntity.RegionId;
IEnumerable<StopEntity> diffStops = await diffStorage.StopStore.GetAllStops(regionId);
await PublishStopsToEmbeddedSocial(diffStops, regionId, publishStorage, publishMetadataStorage, embeddedSocial, runId);
});
tasks.Add(task);
}
await Task.WhenAll(tasks.ToArray());
}