Bedrock.JobQueue.Consumer.LeaseExtender (bedrock_job_queue v0.2.0)
View SourcePeriodically extends a lease while a job is being processed.
Per QuiCK paper Algorithm 3: Workers should extend leases in parallel with job execution to prevent long-running jobs from losing their lease.
Behavior
- Started via
start/5which spawns a linked process - The process loops, extending the lease at regular intervals
- Stopped via
stop/1when the job completes (sends:stopmessage) - Uses
spawn_linkso the extender dies if the parent job process crashes - Extension failures are logged but don't stop the loop - the job may still complete in time before the lease expires
- If the lease cannot be extended (e.g., already expired), logging occurs but execution continues
Timing
By default, the extender runs every lease_duration / 3 milliseconds and
extends the lease by lease_duration milliseconds. This ensures the lease
is extended well before expiration even if one extension attempt fails.
Summary
Functions
@spec start(module(), term(), Bedrock.JobQueue.Lease.t(), pos_integer(), keyword()) :: pid()
Starts a lease extender process.
Options:
:interval- How often to extend the lease in ms (default: lease_duration / 3):extension- How much to extend by in ms (default: lease_duration)
Returns the pid of the extender process.
@spec stop(pid()) :: :ok
Stops a lease extender process.