Table of Contents

Method EnqueueAsync

Namespace
Millrace.Storage.SqlServer
Assembly
Millrace.Storage.SqlServer.dll

EnqueueAsync(IReadOnlyList<JobRecord>, CancellationToken)

Inserts jobs all-or-nothing and returns their effective ids positionally.

public ValueTask<IReadOnlyList<JobId>> EnqueueAsync(IReadOnlyList<JobRecord> jobs, CancellationToken ct)

Parameters

jobs IReadOnlyList<JobRecord>
ct CancellationToken

Returns

ValueTask<IReadOnlyList<JobId>>

Remarks

Idempotency (§4.2.6). A record whose (TenantId, IdempotencyKey) matches an active job inserts nothing; its position returns the existing job's id. This linearizes against terminal transitions: each position always returns either the previously-active holder's id or the new job's id, even when the holder goes terminal concurrently.

Continuation fixup. An Awaiting record whose parent is already terminal resolves inside the same transaction: parent Succeeded ⇒ inserted as Enqueued; parent Dead/Cancelled ⇒ inserted as Cancelled; parent missing ⇒ MillraceParentJobNotFoundException (and the whole batch rolls back). The insert MUST be mutually serializable with the parent's terminal ApplyAsync(JobTransition, CancellationToken): once both commit, in either order, the child is Enqueued/Cancelled — never left Awaiting. (Relational guidance: lock the parent row during the fixup lookup.)

Caller contract (engine-guaranteed; providers may reject with ArgumentException, the conformance kit does not test it): no two records in one batch share a non-null idempotency key; states are Scheduled/Enqueued/Awaiting only. A duplicate JobId throws and persists nothing.