runner.bend relies on unsafe/foreign
raw source on the hub · import bend-kit-runner@0.19.0.0/runner.bend as Runner
Durable job runner: a journaled scheduler queue, bounded by a resources pool, with retry and a breaker per target. Source: https://github.com/paymog/bend-kit/tree/main/runner
10 imports
import Base import ./model.bend as Model import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes import bend-kit-journal@0.3.1.1/journal.bend as J import bend-kit-scheduler@0.4.3.0/queue.bend as Q import bend-kit-resources@0.1.0.0/resources.bend as Res import bend-kit-retry@0.3.0.0/retry.bend as Retry import bend-kit-time@0.3.0.0/time.bend as Time import bend-kit-collections@0.1.5.0/heap.bend as H import bend-kit-files@0.4.0.0/files.bend as Files
Types
type Config source · line 18 · raw
Data
policy: retry's policy for each ticket. circuit: the breaker of each target. idle: ms that drain waits when no attempt started. compact: tick compacts the journal once records past this many octets were appended since open or the last compaction; 0 never.
Config@policy:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @circuit:0x14e48621ef66156b0eb652524b8594d4/retry.Circuit -> @idle:U32 -> @compact:U32 -> Config
type Log source · line 22 · raw
Type
The journal, its path, its file cap, and its length at open or at the last compaction.
Log@journal:0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal -> @path:String -> @limit:U32 -> @base:U32 -> Log
type Flight source · line 26 · raw
@-A:Data -> Type
An attempt that runs: its unit of the pool, the budget that admit left, and its target.
Flight@-A:Data -> @ticket:0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A> -> @grant:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @budget:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @target:String -> Flight<A>
type Msg source · line 33 · raw
@-A:Data -> Type
A message to the owner: an attempt's outcome, or another fiber's durable queue operation.
Ended@-A:Data -> @id:Nat -> @outcome:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> Msg<A>
Add@-A:Data -> @deadline:Nat -> @payload:A -> @reply:Chan(Out(Nat)) -> Msg<A>
Drop@-A:Data -> @id:Nat -> @reply:Chan(Out(Unit)) -> Msg<A>
ReviveAsk@-A:Data -> @id:Nat -> @deadline:Nat -> @reply:Chan(Out(Unit)) -> Msg<A>
PurgeAsk@-A:Data -> @before:Nat -> @reply:Chan(Out(Unit)) -> Msg<A>
PurgeAllAsk@-A:Data -> @reply:Chan(Out(Unit)) -> Msg<A>
type Runner source · line 43 · raw
@-A:Data -> Type
An open runner. Replaying its journal gives its state; its pool bounds the attempts that run at once. Each attempt sends its outcome, and each other fiber its ask, on inbox. flights are the attempts that run.
Runner@-A:Data -> @log:Log -> @state:0x93b55640cccb9195b4b71fdc6bb0e097/model.State<A> -> @pool:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @config:Config -> @inbox:Chan(Msg<A>) -> @flights:List<&1, Flight<A>> -> Runner<A>
type Swap source · line 418 · raw
Type
Kept: compaction failed before the rename, and the old journal stands. Stranded: the rename happened, but the new journal did not open. Moved: the journal at path is the snapshot.
Kept@err:Pair(U32, String) -> Swap
Stranded@err:Pair(U32, String) -> Swap
Moved@journal:0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal -> Swap
Definitions
def Out source · line 29 · raw
@-X:Type -> Type
def Claimed source · line 47 · raw
@-A:Data -> Type
The runner, the claim fuel left, and the first error.
def Ran source · line 50 · raw
@-A:Data -> Type
def clock source · line 54 · raw
IO(Nat)
Wall-clock ms since the Unix epoch. Deadlines must keep their meaning across a restart.
def first source · line 59 · raw
@a:Out(Unit) -> @b:Out(Unit) -> Out(Unit)
def log.appended source · line 66 · raw
@+path:String -> @+limit:U32 -> @+base:U32 -> @x:Pair(0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal, Out(Unit)) -> Pair(Log, Out(Unit))
def log.append source · line 70 · raw
@l:Log -> @p:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Pair(Log, Out(Unit)))
def log.close source · line 76 · raw
@l:Log -> IO(Unit)
def log.of source · line 81 · raw
@j:0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal -> @+max:U32 -> @path:String -> @+limit:U32 -> Log
The journal reads with limit as its record cap, so that a snapshot fits; appends keep max.
def enqueue.done source · line 100 · raw
@-A:Data -> @+id:Nat -> @y:Ran(A) -> Pair(Runner<A>, Out(Nat))
def inbox source · line 134 · raw
@-A:Data -> @r:Runner<A> -> Pair(Runner<A>, Chan(Msg<A>))
The runner back, and its inbox for asks from other fibers.
def ask.answer source · line 138 · raw
@-X:Type -> @m:Maybe<&1, Out(X)> -> Out(X)
def ask.sent source · line 145 · raw
@-A:Data -> @-X:Type -> @x:Result<&1, &1, Msg<A>, Unit> -> @+rep:Chan(Out(X)) -> IO(Out(X))
def ask source · line 155 · raw
@-A:Data -> @-X:Type -> @+ib:Chan(Msg<A>) -> @m:(@_:Chan(Out(X)) -> Msg<A>) -> IO(Out(X))
Sends m, built with a new reply channel, on the inbox and waits for the reply.
def ask.enqueue source · line 163 · raw
@-A:Data -> @+ib:Chan(Msg<A>) -> @+deadline:Nat -> @x:A -> IO(Out(Nat))
From another fiber: adds a job due at deadline, and answers its ticket id once the record is durable. The answer comes when the fiber that owns the runner reads the inbox, in tick or drain.
def ask.cancel source · line 167 · raw
@-A:Data -> @+ib:Chan(Msg<A>) -> @+id:Nat -> IO(Out(Unit))
From another fiber: cancels ticket id, as cancel does. The answer comes when the owner reads the inbox.
def ask.revive source · line 170 · raw
@-A:Data -> @+ib:Chan(Msg<A>) -> @+id:Nat -> @+deadline:Nat -> IO(Out(Unit))
def ask.purge source · line 173 · raw
@-A:Data -> @+ib:Chan(Msg<A>) -> @+before:Nat -> IO(Out(Unit))
def ask.purge.all source · line 176 · raw
@-A:Data -> @+ib:Chan(Msg<A>) -> IO(Out(Unit))
def release source · line 181 · raw
@-A:Data -> @r:Runner<A> -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> Runner<A>
def claim.held source · line 185 · raw
@-A:Data -> @y:Ran(A) -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))
def claim.tag source · line 192 · raw
@-A:Data -> @+id:Nat -> @o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> IO(Msg<A>)
def settle.done source · line 276 · raw
@-A:Data -> @y:Ran(A) -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))
def random source · line 301 · raw
@r:Out(U32) -> Nat
def take.keep source · line 308 · raw
@-A:Data -> @m:Maybe<&1, Flight<A>> -> @xs:List<&1, Flight<A>> -> List<&1, Flight<A>>
def take.at source · line 315 · raw
@-A:Data -> @eq:Bool -> @f:Flight<A> -> @r:Pair(Maybe<&1, Flight<A>>, List<&1, Flight<A>>) -> Pair(Maybe<&1, Flight<A>>, List<&1, Flight<A>>)
def take source · line 325 · raw
@-A:Data -> @fs:List<&1, Flight<A>> -> @+id:Nat -> Pair(Maybe<&1, Flight<A>>, List<&1, Flight<A>>)
The flight of ticket id, and the other flights.
def asked.failed source · line 353 · raw
@-A:Data -> @-X:Type -> @+rep:Chan(Out(X)) -> @r:Runner<A> -> @+c:U32 -> @+m:String -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Nat -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))
Sends the failure to the asker, and keeps it as the round's error.
def asked.fail source · line 359 · raw
@-A:Data -> @-X:Type -> @+rep:Chan(Out(X)) -> @r:Runner<A> -> @e:Pair(U32, String) -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Nat -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))
def added source · line 364 · raw
@-A:Data -> @+rep:Chan(Out(Nat)) -> @y:Pair(Runner<A>, Out(Nat)) -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Nat -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))
def dropped source · line 374 · raw
@-A:Data -> @+rep:Chan(Out(Unit)) -> @y:Ran(A) -> @fuel:Nat -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Nat -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))
def merged source · line 401 · raw
@-A:Data -> @e:Out(Unit) -> @k:Claimed(A) -> Claimed(A)
def flights.none source · line 407 · raw
@-A:Data -> @fs:List<&1, Flight<A>> -> Pair(List<&1, Flight<A>>, Bool)
The flights back, and whether none runs.
def swap.reopened source · line 423 · raw
@x:Out(Pair(0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal, Unit)) -> Swap
def swap.renamed source · line 431 · raw
@+path:String -> @+limit:U32 -> @x:Out(Unit) -> IO(Swap)
The reopen fsyncs the directory, so the rename is durable before the next append.
def swap.written source · line 440 · raw
@+path:String -> @+tmp:String -> @+limit:U32 -> @x:Pair(0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal, Out(Unit)) -> IO(Swap)
def swap.opened source · line 452 · raw
@+path:String -> @+tmp:String -> @+limit:U32 -> @x:Out(Pair(0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal, Unit)) -> @snap:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Swap)
def swap source · line 462 · raw
@+path:String -> @+limit:U32 -> @snap:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Swap)
Writes snap as the only record of path.compact, fsyncs it, and renames it over path.
def log.stop source · line 469 · raw
@j:0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal -> 0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal
def compact.moved source · line 473 · raw
@x:Swap -> @j:0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal -> @+max:U32 -> @path:String -> @+limit:U32 -> @+base:U32 -> IO(Pair(Log, Out(Unit)))
def compact.done source · line 493 · raw
@-A:Data -> @x:Pair(Log, Out(Unit)) -> @s:0x93b55640cccb9195b4b71fdc6bb0e097/model.State<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @c:Config -> @ib:Chan(Msg<A>) -> @fs:List<&1, Flight<A>> -> Ran(A)
def tick.ran source · line 507 · raw
@e:Out(Unit) -> @b:Bool -> Out(Bool)
def tick.compacted source · line 514 · raw
@-A:Data -> @+b:Bool -> @y:Ran(A) -> Pair(Runner<A>, Out(Bool))
def tick.polled source · line 541 · raw
@-A:Data -> @x:Poll<&1, &1, Maybe<&1, Msg<A>>, Unit> -> Maybe<&1, Msg<A>>
def tick.wait source · line 548 · raw
@-A:Data -> @t:Pair(List<&1, Flight<A>>, Bool) -> @j:Log -> @s:0x93b55640cccb9195b4b71fdc6bb0e097/model.State<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @c:Config -> @+ib:Chan(Msg<A>) -> IO(Pair(Runner<A>, Maybe<&1, Msg<A>>))
def tick.next source · line 562 · raw
@-A:Data -> @r:Runner<A> -> IO(Pair(Runner<A>, Maybe<&1, Msg<A>>))
The next message. While an attempt runs, it waits for one; when none runs, it takes one only when the inbox holds one.
def finished.of source · line 612 · raw
@-A:Data -> @+quiet:Bool -> @t:Pair(List<&1, Flight<A>>, Bool) -> @j:Log -> @s:0x93b55640cccb9195b4b71fdc6bb0e097/model.State<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @c:Config -> @ib:Chan(Msg<A>) -> Pair(Runner<A>, Bool)
def finished source · line 618 · raw
@-A:Data -> @r:Runner<A> -> Pair(Runner<A>, Bool)
The runner back, and whether no ticket is pending or running and no attempt runs.
def drain.handled source · line 622 · raw
@-A:Data -> @t:Pair(Runner<A>, Out(Bool)) -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))
def drain.end source · line 684 · raw
@-A:Data -> @x:Pair(Runner<A>, Bool) -> Ran(A)
def orphans.next source · line 698 · raw
@-A:Data -> @y:Ran(A) -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Ran(A))) -> IO(Ran(A))
def close.answer source · line 712 · raw
@-A:Data -> @m:Msg<A> -> IO(Unit)
def close.polled source · line 737 · raw
@-A:Data -> @x:Poll<&1, &1, Maybe<&1, Msg<A>>, Unit> -> @next:(@_:Unit -> IO(Unit)) -> IO(Unit)
def close.drain source · line 749 · raw
@-A:Data -> @fuel:Nat -> @+ib:Chan(Msg<A>) -> IO(Unit)
Answers each ask left in the closed inbox with a failure. fuel bounds the messages it reads.
def close source · line 759 · raw
@-A:Data -> @r:Runner<A> -> IO(Unit)
Closes the inbox and the journal. Each ask still in the inbox gets a failure, and no op is appended for it.
def open.done source · line 766 · raw
@-A:Data -> @y:Ran(A) -> IO(Out(Runner<A>))
def state source · line 801 · raw
@-A:Data -> @r:Runner<A> -> Pair(Runner<A>, 0x93b55640cccb9195b4b71fdc6bb0e097/model.State<A>)
The runner back, and a copy of its state.
Templates
template commit.done source · line 85 · raw
@-A:Data -> @x:Pair(Log, Out(Unit)) -> @s:0x93b55640cccb9195b4b71fdc6bb0e097/model.State<A> -> @+op:0x93b55640cccb9195b4b71fdc6bb0e097/model.Op<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @c:Config -> @ib:Chan(Msg<A>) -> @fs:List<&1, Flight<A>> -> Ran(A)
template commit source · line 94 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+op:0x93b55640cccb9195b4b71fdc6bb0e097/model.Op<A> -> IO(Ran(A))
Appends op, and applies it once the append is durable. After a failed append the state is as it was, and the journal refuses every later append until the runner is reopened.
template enqueue source · line 108 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+deadline:Nat -> @x:A -> IO(Pair(Runner<A>, Out(Nat)))
Adds a job that is due at deadline (wall-clock ms) and answers its ticket id once the record is durable.
template cancel source · line 115 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+id:Nat -> IO(Ran(A))
Cancels ticket id. A running attempt finishes, but its ticket is never selected again. A dead ticket is dropped.
template revive source · line 120 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+id:Nat -> @+deadline:Nat -> IO(Ran(A))
Makes dead ticket id pending again at deadline (wall-clock ms), with its payload and a new retry budget. A ticket that is not dead does not change.
template purge source · line 124 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+before:Nat -> IO(Ran(A))
Drops, as one record, the dead tickets that retry gave up on before before (wall-clock ms).
template purge.all source · line 128 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> IO(Ran(A))
Drops every dead ticket, as one record.
template trip.if source · line 195 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @same:Bool -> @r:Runner<A> -> @+key:String -> @st:0x14e48621ef66156b0eb652524b8594d4/retry.State -> IO(Ran(A))
template trip source · line 203 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+key:String -> @+old:0x14e48621ef66156b0eb652524b8594d4/retry.State -> @br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> IO(Ran(A))
Appends a Break when the target's breaker left old, so that a reopen restores it.
template claim.go source · line 207 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @gate:0x14e48621ef66156b0eb652524b8594d4/retry.Gate -> @+br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+key:String -> @r:Runner<A> -> @+id:Nat -> @d:Nat -> @+x:A -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))
template claim.tripped source · line 220 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @y:Ran(A) -> @gate:0x14e48621ef66156b0eb652524b8594d4/retry.Gate -> @+br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+key:String -> @+id:Nat -> @d:Nat -> @+x:A -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))
template claim.gate source · line 229 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @a:Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Breaker, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, 0x14e48621ef66156b0eb652524b8594d4/retry.Gate)) -> @+key:String -> @+old:0x14e48621ef66156b0eb652524b8594d4/retry.State -> @r:Runner<A> -> @+id:Nat -> @d:Nat -> @+x:A -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))
A change to the breaker is durable before the attempt starts.
template claim.admit source · line 237 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @r:Runner<A> -> @t:0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A> -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))
The selected ticket asks its target's breaker and its own budget for an attempt.
template claim.selected source · line 247 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @y:Ran(A) -> @t:0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A> -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))
template claim.pick source · line 255 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+left:Nat -> @+now:Nat -> @k:0x93b55640cccb9195b4b71fdc6bb0e097/model.Pick<A> -> @j:Log -> @s:0x93b55640cccb9195b4b71fdc6bb0e097/model.State<A> -> @c:Config -> @ib:Chan(Msg<A>) -> @fs:List<&1, Flight<A>> -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))
template claim source · line 267 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @fuel:Nat -> @+now:Nat -> @r:Runner<A> -> IO(Claimed(A))
Starts an attempt for each due ticket while the pool has a free unit; each attempt sends its outcome on the inbox. fuel bounds the tickets taken, and the fuel left comes back.
template settle.br source · line 280 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @+op:0x93b55640cccb9195b4b71fdc6bb0e097/model.Op<A> -> @y:Ran(A) -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))
template settle.op source · line 292 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @+o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+id:Nat -> @+key:String -> @+now:Nat -> @+rnd:Nat -> @r:Runner<A> -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))
Tells the target's breaker, appends the outcome's op, and returns the attempt's unit to the pool. The op of a cancelled ticket changes no state: the queue no longer holds it.
template settle.flight source · line 332 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @mf:Maybe<&1, Flight<A>> -> @+o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @+now:Nat -> @+rnd:Nat -> @r:Runner<A> -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))
template settle.take source · line 340 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @t:Pair(Maybe<&1, Flight<A>>, List<&1, Flight<A>>) -> @+o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @+now:Nat -> @+rnd:Nat -> @j:Log -> @s:0x93b55640cccb9195b4b71fdc6bb0e097/model.State<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @c:Config -> @ib:Chan(Msg<A>) -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))
template settle source · line 347 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @+id:Nat -> @+o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @+now:Nat -> @+rnd:Nat -> @r:Runner<A> -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))
Settles the flight of ticket id with outcome o.
template handle source · line 385 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @m:Msg<A> -> @+now:Nat -> @+rnd:Nat -> @r:Runner<A> -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Nat -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))
Settles an attempt or commits and answers an ask; enqueue and revive each add one claim.
template compact.if source · line 484 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @ok:Bool -> @j:0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal -> @+max:U32 -> @+path:String -> @+limit:U32 -> @+base:U32 -> @s:0x93b55640cccb9195b4b71fdc6bb0e097/model.State<A> -> IO(Pair(Log, Out(Unit)))
template compact source · line 500 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> IO(Ran(A))
Writes the state as one Snap record into a new journal, fsyncs it, and renames it over the old one. A crash leaves one of the two journals, and both replay to this state. After a failure the old journal stands; when the failure came after the rename, appends stop until the runner is reopened.
template tick.due source · line 518 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @due:Bool -> @+b:Bool -> @r:Runner<A> -> IO(Pair(Runner<A>, Out(Bool)))
template tick.size source · line 527 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+b:Bool -> IO(Pair(Runner<A>, Out(Bool)))
template tick.grown source · line 534 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @t:Pair(Runner<A>, Out(Bool)) -> IO(Pair(Runner<A>, Out(Bool)))
Compacts once the journal grew past Config.compact octets since open or the last compaction.
template tick.got source · line 567 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @x:Pair(Runner<A>, Maybe<&1, Msg<A>>) -> @+ran:Bool -> @+left:Nat -> @err:Out(Unit) -> @next:(@_:Claimed(A) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))
Handles the message, then claims due tickets into free units with the claim fuel left. None ends the round.
template tick.run source · line 582 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @fuel:Nat -> @+ran:Bool -> @k:Claimed(A) -> IO(Pair(Runner<A>, Out(Bool)))
Handles messages until no attempt runs and the inbox is empty. fuel bounds the messages; attempts that still run when it ends stay in the runner, and the next tick settles them.
template tick.at source · line 595 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @r:Runner<A> -> IO(Pair(Runner<A>, Out(Bool)))
Fuel for each pending ticket, each attempt that may already run, and the last look at the inbox.
template tick source · line 606 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @r:Runner<A> -> IO(Pair(Runner<A>, Out(Bool)))
One round: start an attempt for each due ticket the pool admits. Then read the inbox: as each attempt finishes, record its outcome, return its unit, and start the next due ticket in that unit; append and answer each ask from another fiber. The round ends when no attempt runs and the inbox is empty. Then compact the journal when it grew past Config.compact. Done{True} when an attempt ran or an ask was answered. work runs on its own; target names the breaker that guards it.
template drain.woke source · line 629 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+idle:U32 -> @x:Poll<&1, &1, Maybe<&1, Msg<A>>, Unit> -> @r:Runner<A> -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))
template drain.poll source · line 645 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+ms:U32 -> @r:Runner<A> -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))
template drain.wait source · line 652 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+idle:U32 -> @r:Runner<A> -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))
template drain.ticked source · line 659 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+idle:U32 -> @t:Pair(Runner<A>, Out(Bool)) -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))
template drain.if source · line 669 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @done:Bool -> @r:Runner<A> -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))
template drain.at source · line 680 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @x:Pair(Runner<A>, Bool) -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))
template drain source · line 691 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @fuel:Nat -> @r:Runner<A> -> IO(Ran(A))
Ticks until no ticket is pending or running and no attempt runs. After a round that did nothing, it waits for a message up to idle ms, or until the earliest pending ticket is due when that is sooner, and handles one that arrives at once. Fails when fuel rounds leave work.
template orphans source · line 703 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @ts:List<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>> -> @+now:Nat -> @r:Runner<A> -> @err:Out(Unit) -> IO(Ran(A))
A running ticket at open lost its attempt in a crash: it is requeued at now, as a failed attempt.
template open.got source · line 775 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @x:Out(Pair(0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal, Maybe<&2, 0x93b55640cccb9195b4b71fdc6bb0e097/model.State<A>>)) -> @+max:U32 -> @path:String -> @+limit:U32 -> @c:Config -> @+capacity:Nat -> IO(Out(Runner<A>))
template open source · line 795 · raw
@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @+path:String -> @+max:U32 -> @+limit:U32 -> @c:Config -> @+capacity:Nat -> IO(Out(Runner<A>))
Opens the runner at path: replays its journal into the state, then requeues each ticket that was running. capacity bounds the attempts that run at once. max caps an op record's octets; limit caps the journal file and a snapshot. Fails when the journal fails to open, or a committed record is not a snapshot or an op.