Esempio n. 1
0
        async Task PurgeOrchestrationHistorySegmentAsync(
            TableQuerySegment <OrchestrationStateEntity> orchestrationStateEntitySegment)
        {
            var stateEntitiesToDelete = new List <OrchestrationStateEntity>(orchestrationStateEntitySegment.Results);

            var historyEntitiesToDelete = new ConcurrentBag <IEnumerable <OrchestrationHistoryEventEntity> >();
            await Task.WhenAll(orchestrationStateEntitySegment.Results.Select(
                                   entity => Task.Run(async() =>
            {
                IEnumerable <OrchestrationHistoryEventEntity> historyEntities =
                    await
                    tableClient.ReadOrchestrationHistoryEventsAsync(
                        entity.State.OrchestrationInstance.InstanceId,
                        entity.State.OrchestrationInstance.ExecutionId).ConfigureAwait(false);

                historyEntitiesToDelete.Add(historyEntities);
            })));

            List <Task> historyDeleteTasks = historyEntitiesToDelete.Select(
                historyEventList => tableClient.DeleteEntitesAsync(historyEventList)).Cast <Task>().ToList();

            // need to serialize history deletes before the state deletes so we dont leave orphaned history events
            await Task.WhenAll(historyDeleteTasks).ConfigureAwait(false);

            await Task.WhenAll(tableClient.DeleteEntitesAsync(stateEntitiesToDelete)).ConfigureAwait(false);
        }