Expand description
The record a pull keeps on disk, so a download outlives the process that started it.
One directory per pull under <data>/pulls/<id>/: the descriptor
(job.json, written once), the live record (status.json, rewritten as the
transfer moves), an append-only history (events.jsonl), the lock a worker
holds for as long as it runs, and the control file a client writes to ask
for a pause or a cancel.
Nothing here starts, signals, or waits on a process: this module owns the format and the rules, the runtime owns the worker.
The liveness rule rests on Unix advisory locks (flock), where a lock
belongs to an open file description rather than to a process. Readers take a
shared lock to test, so they never exclude one another; a worker takes the
exclusive one.
Structs§
- Pull
Event - One line of a job’s history.
- PullJob
- A pull’s descriptor: what was asked for, written once when the job is created.
- Pull
JobDir - One pull’s directory: its descriptor, and the files around it.
- Pull
Lock - A worker’s claim on a job, held for as long as the worker runs. Dropping it releases the lock, and so does the process ending for any reason, which is what makes a lost worker detectable.
- Pull
Status - A pull’s live record, rewritten as the transfer moves.
- Pull
Store - The directory of pull jobs.
Enums§
- Pull
Control - What a client asked a running worker to do.
- Pull
Error - A failure reading or writing a pull’s record.
- Pull
Event Kind - What a history line records. Progress is deliberately absent: it belongs in the rewritten status, not in a file that only grows.
- Pull
State - Where a pull is in its life.
Constants§
- REGISTERING_
LINE - The status line a worker writes while it registers what it fetched. The scan it names is the one stretch of a job that reads no control file, so the line doubles as the mark of a job past stopping.
- START_
GRACE_ MS - How long a job queued with no worker is given before it counts as abandoned. A worker writes its pid as soon as it holds the job, which it does within milliseconds of starting, so this is generous rather than tuned.
Functions§
- take_
lock - Take an exclusive lock on
path, creating it if it is not there, orNonewhen someone else holds it. The lock lives with the returned handle.