Skip to main content

work_loop

Function work_loop 

Source
pub fn work_loop(
    receiver: &Receiver<Wake>,
    handlers: &GitHandlers,
    busy: &AtomicUsize,
    push_retries: PushRetries,
)
Expand description

What: Runs the after-commit work of each repository named, one repository at a time, folding wakes that arrive while it works into the next round, and looks again at a repository whose claims another instance held when their lease is over. Why: Draining claims everything pending, so a burst of wakes for one repository is one pass. The instance that held a claim may have died, and nothing but this loop would then wake the work: it waits for a wake no longer than the first lease still running, and the service counts itself busy meanwhile, so it does not exit idle with work claimed by a dead holder. The same holds for a push the service stopped: the loop owns the plan of its new tries (PushRetries), each round hands the workers what is due and applies what they ask, and the wake for the earliest plan is kept in the same schedule as the lease wakes, so the service neither forgets the plan nor exits idle while a try is pending.

In TS you’d write (pseudocode):

for await (const dir of wakesOrDueRetries) await drain(dir, handlers)