Tm1Batch
using Skipcheck.Tm1.Client; A JSON $batch being put together, from Tm1Client.Batch: calls made
through Client are queued rather than sent, and RunAsync sends them
together. Each call's result is there once the batch has run. Every service's methods
work through it unchanged. TM1 (11.8) runs the calls in the order they were made, so a
later call sees an earlier one's writes. See Tm1SessionBatch for what else TM1
does with a batch.
Read three things in one round trip:
// Each call is queued as it's made, and has its result once the batch has run.
// A list is queued when its enumeration starts, so start it before running.
var batch = tm1.Batch();
var sales = batch.Client.Cubes.GetAsync("Sales");
var region = batch.Client.Dimensions.GetAsync("Region");
var processes = batch.Client.Processes.ListAsync(ODataQuery.None().Select(Process.Fields.Name)).ToListAsync().AsTask();
await batch.RunAsync();
return (await sales, await region, await processes);
Create many elements in batches of 200, each failure kept to its own element:
// One request per element, 200 to a $batch; one element's failure is its own
var batch = tm1.Batch();
async Task<string> Create(string city)
{
try
{
var created = await batch.Client.Elements.CreateAsync("City", "City", ElementPatch.Builder().Name(city).Build());
return created.Name!;
}
catch (Tm1Exception e)
{
return $"{city} failed: {e.Message}";
}
}
var results = cities.Select(Create).ToList(); // ToList makes the calls now, which queues them
await batch.RunAsync(200);
return await Task.WhenAll(results);
Members
Client property | The client whose calls join this batch. |
Size | How many requests have joined. |
RunAsync | Sends the queued requests (Tm1SessionBatch.RunAsync); completes when every call has its result. |
RunAsync | Sends the queued requests, at most perRequest to each $batch; completes when every call has its result. |
Client
propertyTm1Client ClientThe client whose calls join this batch.
Size
int Size()How many requests have joined.
RunAsync
Task RunAsync(CancellationToken cancellationToken = default)Sends the queued requests
(Tm1SessionBatch.RunAsync); completes when every call has
its result.
RunAsync
Task RunAsync(int perRequest, CancellationToken cancellationToken = default)Sends the queued requests, at most perRequest to each
$batch; completes when every call has its result.