Method EnqueueBatchAsync
- Namespace
- Millrace
- Assembly
- Millrace.dll
EnqueueBatchAsync(JobBatch, CancellationToken)
Enqueues a batch in one round trip and one transaction, returning the effective ids positionally.
public ValueTask<IReadOnlyList<JobId>> EnqueueBatchAsync(JobBatch batch, CancellationToken ct = default)
Parameters
batchJobBatchctCancellationToken
Returns
Examples
var batch = new JobBatch();
foreach (var id in orderIds)
{
batch.Enqueue<IEmailSender>(s => s.SendAsync(id));
}
await jobs.EnqueueBatchAsync(batch);
Remarks
All-or-nothing: every job lands or none does. A partially-enqueued fan-out is worse than none, because the caller cannot tell which half landed and retrying duplicates the rest.
Ids are returned by position, and a position whose idempotency key was already held returns the existing job's id rather than a new one โ the same rule a single enqueue follows (ยง4.2.6).
Exceptions
- ArgumentException
Two jobs in
batchshare an idempotency key. Keys are unique among active jobs, so the second would silently resolve to the first. Rejected here rather than at the database, where the storage contract leaves it to the provider โ left alone, the same batch would deduplicate on one engine and violate a unique index on another.