Expand description
The durable work-item record for asynchronous work (review, push, maintenance) left for a resident consumer.
What:
The durable work-item record: a small file in the Git directory that says “this landed object needs this
asynchronous work”, written by the wrapper and drained by a separate resident consumer.
Why:
A wrapper process exits when its command ends, and it may start no program, so work that must not delay a landing
(the standards review, later auto-push and maintenance) is left as a record instead. The record is generic: a kind,
the landed object and an id derived from both, so a retry cannot duplicate it. The design, its failure cases and
the consumer contract are in doc/planning/cli-git-standards-review-port.md. Nothing calls this yet.
In TS you’d write (pseudocode):
await enqueue(workDir, { kind: 'review', oid, ... }); const item = await claimNext(workDir); await finish(workDir, item);Re-exports§
pub use crate::work_item_recovery::Recovered;pub use crate::work_item_recovery::next_claim_expiry;pub use crate::work_item_recovery::requeue_expired;pub use crate::work_item_recovery::requeue_expired_reporting;
Structs§
- Claimed
- What: A held item: the decoded record, its id, and the name of the file that holds it. Why: Finishing needs the claim’s file name, not the id: the name carries the generation of the claim, so a settlement or a renewal reaches only the claim it was made for. The consumer needs the item.
- Work
Item - What: One work item: what to do, to which landed object, and where. Why: The consumer needs only the object name and the places to find the repository; it reads the patch itself.
Enums§
- Enqueued
- What: Whether an enqueue added the item or found it already known. Why: A landing that is replayed, or a daemon that restarts, enqueues again; the second time must change nothing.
- Work
Kind - What: The kind of work an item asks for. Why: One record format carries every asynchronous job; the kind picks the consumer’s handler.
Constants§
- CLAIMED
- Held by one consumer, with a lease.
- DONE
- Finished.
- FAILED
- Given up after too many tries.
- PENDING
- The state directories, in the order an item moves through them.
- RECOVERING
- Held by one instance that is returning an expired claim to
pending; seerequeue_with. - VERSION
- The record format version.
- WORK_
DIRECTORY - Directory under the worktree’s own Git directory (
WorkItem::git_dir) that holds the state directories.
Functions§
- claim_
file_ name - What:
The name of the file that holds the claim of
idof the generationtokenas of the readingstamp. Why: The generation is unique to one acquisition and the reading says when the holder last proved it was alive, so the name alone tells every other instance whose claim this is and whether it ran out, and a rename of exactly that name is the only way to take it: a holder that renews changes the name, so a take made from an older look finds nothing to take. - claim_
next - What:
Claim the oldest pending item by renaming it into
claimedunder a name that carries a fresh generation and the readingnow. A record that does not decode is moved tofailedso it cannot block the queue. Why: A rename is atomic: of two consumers racing for one item, the loser sees the file gone and takes the next one. The generation and the reading are in the name, so the claim is whole from the instant it exists; nothing is written to it. - claim_
next_ of - What: Claim the oldest pending item of the given kinds, leaving every other kind where it is. Why: Consumers of different kinds share one queue; the kind starts the file name, so a consumer never opens, moves or stamps an item that belongs to another.
- enqueue
- What: Write the item as a pending record, whole or absent, unless its id is already in any state. The producer never waits for a consumer and never reads anything back. Why: The id is the idempotency key; the exclusive publish makes two racing producers agree on one winner.
- find_
claim - The path of the file that holds the claim of
idnow, or nothing when it is not claimed or being recovered. - id_
of_ entry - What:
The id an entry of
claimedorrecoveringis the claim of: the part of its name before the generation. Why: A claim by an earlier release is named by the id alone, so a name with no separator is its own id. - oldest_
pending_ age - What:
How long the oldest pending item has waited, or
Nonewhen nothing is pending. Why: The wrapper’s one-line notice that no consumer is draining the queue is this age past a bound; a process id in a file would be meaningless across process-id namespaces. - renew_
claim - What:
Start the lease of the claim file
nameagain atnow, returning its new name; nothing when the claim is no longer inclaimedunder that name or its modification time could not be set. Why: A holder that is still working must not look abandoned: every consumer of a directory that several consumers drain reads the reading in the name as the proof of life. The renewal is a rename of the exact name the holder last wrote, so a claim that was taken over, settled, or taken over and claimed again by someone else is not found and is never brought back or renewed on the other’s behalf; and an instance that looked at the old name and means to take it finds nothing. - settle
- What:
Move a claimed item to
done(or tofailed), after the consumer’s result is durable. Why: A crash before this rename leaves the item claimed, and its lease runs out; the work is then done again, so a handler must tolerate a repeat. The rename names the claim’s generation, so a holder whose claim was taken over and claimed again by another settles nothing of the other’s. - settle_
named settlefor the claim filename, whose id is the part of the name before the generation.- state_
directory - The directory of one state.