Open asketagarwal opened 3 years ago
How about a call back design. It avoids the need to correlate request to response.
public Task ProcessBulkOperationsAsync (
IReadOnlyList<BulkItemOperation> operations,
BulkRequestOptions bulkRequestOptions,
CancellationToken cancellationToken)
public abstract class BulkItemOperation
{
static BulkItemOperation ReadItemOperation<T>(
string id,
PartitionKey pk = null,
BulkItemRequestOptions requestOptions = null,
Func<ItemResponse<T>> responseCallBack);
static BulkItemOperation ReadItemStreamOperation<T>(
string id,
PartitionKey pk,
BulkItemRequestOptions requestOptions = null,
Func<ResponseMessage> responseCallBack);
static BulkItemOperation CreateItemOperation<T>(
string id,
PartitionKey pk = null,
BulkItemRequestOptions requestOptions = null,
Func<ItemResponse<T>> responseCallBack);
.......
.......
}
With the callback method, how do we approach the Diagnostics, RequestCharge etc.
One more alternative (offline discussion summary with @ealsur )
public class BulkExecutor
{
void Add<T>(Task<ItemResponse<T>>, object context);
// Not supported ones only fail at runtime
void Add(Task<ResponseMessage>, object context);
BulkResponse Execute(CancellationToken);
}
public class BulkResponse
{
int FailCount { get; }
// TODO: Replace with CosmosDiagnostics?
TimeSpan GetClientElapsedTime();
// Runtime failures in-case of in-correct casting
ResponseMessage GetResponse(object context);
ItemResponse<T> GetResponse<T>(object context);
}
Above alternative fits for WaitAll() contract or still BLOCKING. Also updated requirements with beow
Motivation
To support workloads where Bulk is not always the requirement and it can be a mix of both Bulk and Non-Bulk operations.
Requirements
Pull API
New Public Contracts:
Implementation
It will be implemented using Batch (multiple batch requests).