Skip to main content

cancel_tx

Function cancel_tx 

Source
pub async fn cancel_tx(
    conn: &mut PgConnection,
    job_id: i64,
) -> Result<Option<JobRow>, AwaError>
Expand description

Transaction-participating variant of cancel.

Runs the cancellation on the caller-provided connection conn rather than acquiring its own from a pool. When conn is already inside a transaction — the common case, and a &mut Transaction deref-coerces to &mut PgConnection — the cancel commits or rolls back atomically with the caller’s other work, and the cooperative awa:cancel NOTIFY to a running worker fires only when the caller commits. When conn is a standalone pooled connection the cancel runs in its own transaction.

Internally the cancel runs in a nested transaction — a SAVEPOINT when conn is already in a transaction — so a cancel error rolls back only the cancel rather than poisoning the caller’s transaction.

On the queue-storage engine this skips the best-effort claim-cursor advance that cancel performs after its own commit (it cannot run inside the caller’s transaction); the derived queue depth may briefly over-count by one until later committed rows on the lane are claimed. Counts are unaffected on the canonical engine.