Skip to main content

Module service_work

Module service_work 

Source
Expand description

The service’s consumer of after-commit push and upkeep work. What: The service’s consumer of after-commit work: pending push and maintenance work items of one repository are claimed, coalesced, run, settled, and a push that failed leaves a record that the person’s next wrapper command shows. Why: A commit must not wait for the network or for upkeep, so the wrapper leaves a record and the resident service does the work on its own thread (doc/planning/cli-git-resident-service.md, “After-commit work”). The service is the only pusher of the repositories it serves, so no lock is needed: several pending pushes of one branch become one push, and a service that died mid-push is noticed by its successor’s first drain, which takes back every claim it finds, never by a process id. Other kinds of work (the standards review) are never claimed here.

In TS you’d write (pseudocode):

for (const group of coalesce(await claimAll(workDir, ['push', 'maintenance']))) settle(group, await handler(group));

Structs§

GitHandlers
The handlers that run real Git.

Enums§

Verdict
What a handler came to.

Constants§

MAX_TRIES
How many times an item is tried before it is given up on.
SERVICE_KINDS
The kinds of work the service runs itself.
SHARED_CLAIM_LEASE
How long a claim in the common directory of a bare repository goes without a renewal before another linked worktree’s instance runs it again; the holder renews it three times in this span while it works (service_claim_renewal.rs).

Traits§

WorkHandlers
What runs each kind of work.

Functions§

drain
What: Runs everything pending for one repository: takes back the claims an earlier service left, claims every pending push and maintenance item, runs one push per branch and one upkeep per repository, settles the items, and leaves a notice for each failed push. Why: Coalescing keeps a burst of commits to one push; a handler that fails leaves the items in failed, not in a loop.
drain_common_records
What: Runs the records the releases before one service per worktree left in the common directory of a bare repository, from the instance of a linked worktree: nothing for a repository with a main worktree, for a main worktree and for a directory with no commondir. Why: Those releases kept every worktree’s records in the common directory. A repository with a main worktree has an instance whose own directory that is, and it runs them (the main worktree’s current records live there too), so a linked instance must not. A repository whose worktrees are all linked has no such instance, and its pushes would sit there with no notice. Several linked instances may drain the directory at once, so a claim is taken back only after its lease, which the holder renews while it works.
drain_common_records_with_lease
drain_common_records with the lease given, so a test can use a short one.
is_acceptable
What: Whether an item is one this service should act on for this repository. Why: Anyone who can write the work directory can write an item, so the fields that become a directory, a reference or a program argument are checked before they are used.
run_round
What: Runs one round of wakes: keeps each wake’s review credential in memory, drains each named repository once, and forgets the credentials when the repository is done. Why: The credential is held only for the reviews of the round that brought it; a service that restarts before the round runs has none, and its reviews record the plain “no key” outcome.
work_directory
The work directory of a repository.

Type Aliases§

Wake
What a wake message brings: the repository to work on and the review credential that came with it, if any.