public async Task <Changes> PushAsync(string familyId, Changes c) { using CancellationTokenSource source = new(_timeout); c = Dto.affixFamilyId(familyId, c); try { var items = GetPushResponse(c.Items); var categories = GetPushResponse(c.Categories); var purchases = GetPushResponse(c.Purchases); var stores = GetPushResponse(c.Stores); var notSoldItems = GetPushResponse(c.NotSoldItems); await Task.WhenAll(items, categories, purchases, stores, notSoldItems); return(new Changes(items.Result, categories.Result, stores.Result, notSoldItems.Result, purchases.Result)); } catch (OperationCanceledException) { return(Dto.emptyChanges); } catch (CosmosException e) when(e.StatusCode is HttpStatusCode.ServiceUnavailable or HttpStatusCode.InternalServerError or HttpStatusCode.TooManyRequests) { source.Cancel(); return(Dto.emptyChanges); } async Task <Document <T>[]> GetPushResponse <T>(Document <T>[] docs) { var pushBulk = PushBulkCoreAsync( docs: docs, properties: i => new CosmosDocumentProperties(Id: i.Id, Etag: i.Etag, PartitionKey: i.CustomerId), cancel: source.Token); var results = (await pushBulk); return (results .Select(i => i.ServerVersion()) .ToArray()); } }