diff --git a/Sync.cs b/Sync.cs index 9397ec4..cc95160 100644 --- a/Sync.cs +++ b/Sync.cs @@ -167,6 +167,11 @@ await BatchQueueProcess(tableActionQueue_Users, private static async Task BatchQueueProcess(ConcurrentQueue Queue, TableClient tableClient, CancellationToken ct) { List BatchTransactions = new List(); + + // Used to re-queue transactions that cannot be put in this batch + // Such as transactions with a row key that is already present in the batch (cannot perform within the same batch) + + List RequeueTransactions = new List(); // Take items out of the queue until it's empty or the max batch size hit while (!Queue.IsEmpty && BatchTransactions.Count < _maxTableBatchSize) @@ -174,7 +179,24 @@ private static async Task BatchQueueProcess(ConcurrentQueue + x.Entity.PartitionKey == dequeued.Entity.PartitionKey && + x.Entity.RowKey == dequeued.Entity.RowKey)) + { + // Requeue the transaction for next batch as it is already existing in this batch + RequeueTransactions.Add(dequeued); + } + else + { + BatchTransactions.Add(dequeued); + } + + } + } if (BatchTransactions.Any()) @@ -200,6 +222,13 @@ private static async Task BatchQueueProcess(ConcurrentQueue