~/bend-docscommunity

runner.bend relies on unsafe/foreign

raw source on the hub · import bend-kit-runner@0.20.2.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

11 imports
import Base
import ./model.bend as Model
import bend-kit-bytes@0.3.3.1/bytes.bend as Bytes
import bend-kit-journal@0.3.1.3/journal.bend as J
import bend-kit-scheduler@0.4.4.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.1/time.bend as Time
import bend-kit-collections@0.1.6.0/heap.bend as H
import bend-kit-files@0.4.0.1/files.bend as Files
import ./inspect.bend as Inspect

Types

type Config source · line 19 · 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.

type Log source · line 23 · raw

Type

The journal, its path, its file cap, and its length at open or at the last compaction.

type Flight source · line 27 · raw

@-A:Data -> Type

An attempt that runs: its unit of the pool, the budget that admit left, and its target.

type Msg source · line 34 · raw

@-A:Data -> Type

A message to the owner: an attempt's outcome, or another fiber's durable queue operation.

type Runner source · line 44 · 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.

type Swap source · line 419 · 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.

Definitions

def Out source · line 30 · raw

@-X:Type -> Type

def Claimed source · line 48 · raw

@-A:Data -> Type

The runner, the claim fuel left, and the first error.

def Ran source · line 51 · raw

@-A:Data -> Type

def clock source · line 55 · raw

IO(Nat)

Wall-clock ms since the Unix epoch. Deadlines must keep their meaning across a restart.

def first source · line 60 · raw

@a:Out(Unit) -> @b:Out(Unit) -> Out(Unit)

def log.appended source · line 67 · raw

@+path:String -> @+limit:U32 -> @+base:U32 -> @x:Pair(0xb9c6a8952912eecb2aa814630cbfa908/journal.Journal, Out(Unit)) -> Pair(Log, Out(Unit))

def log.append source · line 71 · raw

@l:Log -> @p:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(Log, Out(Unit)))

def log.close source · line 77 · raw

@l:Log -> IO(Unit)

def log.of source · line 82 · raw

@j:0xb9c6a8952912eecb2aa814630cbfa908/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 101 · raw

@-A:Data -> @+id:Nat -> @y:Ran(A) -> Pair(Runner<A>, Out(Nat))

def inbox source · line 135 · 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 139 · raw

@-X:Type -> @m:Maybe<&1, Out(X)> -> Out(X)

def ask.sent source · line 146 · raw

@-A:Data -> @-X:Type -> @x:Result<&1, &1, Msg<A>, Unit> -> @+rep:Chan(Out(X)) -> IO(Out(X))

def ask source · line 156 · 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 164 · 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 168 · 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 171 · raw

@-A:Data -> @+ib:Chan(Msg<A>) -> @+id:Nat -> @+deadline:Nat -> IO(Out(Unit))

def ask.purge source · line 174 · raw

@-A:Data -> @+ib:Chan(Msg<A>) -> @+before:Nat -> IO(Out(Unit))

def ask.purge.all source · line 177 · raw

@-A:Data -> @+ib:Chan(Msg<A>) -> IO(Out(Unit))

def release source · line 182 · raw

@-A:Data -> @r:Runner<A> -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> Runner<A>

def claim.held source · line 186 · raw

@-A:Data -> @y:Ran(A) -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))

def claim.tag source · line 193 · raw

@-A:Data -> @+id:Nat -> @o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> IO(Msg<A>)

def settle.done source · line 277 · 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 302 · raw

@r:Out(U32) -> Nat

def take.keep source · line 309 · raw

@-A:Data -> @m:Maybe<&1, Flight<A>> -> @xs:List<&1, Flight<A>> -> List<&1, Flight<A>>

def take.at source · line 316 · 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 326 · 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 354 · 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 360 · 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 365 · 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 375 · 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 402 · raw

@-A:Data -> @e:Out(Unit) -> @k:Claimed(A) -> Claimed(A)

def flights.none source · line 408 · 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 424 · raw

@x:Out(Pair(0xb9c6a8952912eecb2aa814630cbfa908/journal.Journal, Unit)) -> Swap

def swap.renamed source · line 432 · 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 441 · raw

@+path:String -> @+tmp:String -> @+limit:U32 -> @x:Pair(0xb9c6a8952912eecb2aa814630cbfa908/journal.Journal, Out(Unit)) -> IO(Swap)

def swap.opened source · line 453 · raw

@+path:String -> @+tmp:String -> @+limit:U32 -> @x:Out(Pair(0xb9c6a8952912eecb2aa814630cbfa908/journal.Journal, Unit)) -> @snap:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Swap)

def swap source · line 463 · raw

@+path:String -> @+limit:U32 -> @snap:0xec25e4adfb02e59e4b817801115988ee/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 470 · raw

@j:0xb9c6a8952912eecb2aa814630cbfa908/journal.Journal -> 0xb9c6a8952912eecb2aa814630cbfa908/journal.Journal

def compact.moved source · line 474 · raw

@x:Swap -> @j:0xb9c6a8952912eecb2aa814630cbfa908/journal.Journal -> @+max:U32 -> @path:String -> @+limit:U32 -> @+base:U32 -> IO(Pair(Log, Out(Unit)))

def compact.done source · line 494 · raw

@-A:Data -> @x:Pair(Log, Out(Unit)) -> @s:0x08e52f309002d32aa01c2d0663a904d6/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 508 · raw

@e:Out(Unit) -> @b:Bool -> Out(Bool)

def tick.compacted source · line 515 · raw

@-A:Data -> @+b:Bool -> @y:Ran(A) -> Pair(Runner<A>, Out(Bool))

def tick.polled source · line 542 · raw

@-A:Data -> @x:Poll<&1, &1, Maybe<&1, Msg<A>>, Unit> -> Maybe<&1, Msg<A>>

def tick.wait source · line 549 · raw

@-A:Data -> @t:Pair(List<&1, Flight<A>>, Bool) -> @j:Log -> @s:0x08e52f309002d32aa01c2d0663a904d6/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 563 · 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 613 · raw

@-A:Data -> @+quiet:Bool -> @t:Pair(List<&1, Flight<A>>, Bool) -> @j:Log -> @s:0x08e52f309002d32aa01c2d0663a904d6/model.State<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @c:Config -> @ib:Chan(Msg<A>) -> Pair(Runner<A>, Bool)

def finished source · line 619 · 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 623 · raw

@-A:Data -> @t:Pair(Runner<A>, Out(Bool)) -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))

def drain.end source · line 685 · raw

@-A:Data -> @x:Pair(Runner<A>, Bool) -> Ran(A)

def orphans.next source · line 699 · 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 713 · raw

@-A:Data -> @m:Msg<A> -> IO(Unit)

def close.polled source · line 738 · raw

@-A:Data -> @x:Poll<&1, &1, Maybe<&1, Msg<A>>, Unit> -> @next:(@_:Unit -> IO(Unit)) -> IO(Unit)

def close.drain source · line 750 · 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 760 · 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 767 · raw

@-A:Data -> @y:Ran(A) -> IO(Out(Runner<A>))

def state source · line 802 · raw

@-A:Data -> @r:Runner<A> -> Pair(Runner<A>, 0x08e52f309002d32aa01c2d0663a904d6/model.State<A>)

The runner back, and a copy of its state.

Templates

template commit.done source · line 86 · raw

@-A:Data -> @x:Pair(Log, Out(Unit)) -> @s:0x08e52f309002d32aa01c2d0663a904d6/model.State<A> -> @+op:0x08e52f309002d32aa01c2d0663a904d6/model.Op<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @c:Config -> @ib:Chan(Msg<A>) -> @fs:List<&1, Flight<A>> -> Ran(A)

template commit source · line 95 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @r:Runner<A> -> @+op:0x08e52f309002d32aa01c2d0663a904d6/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 109 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 116 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 121 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 125 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 129 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @r:Runner<A> -> IO(Ran(A))

Drops every dead ticket, as one record.

template trip.if source · line 196 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @same:Bool -> @r:Runner<A> -> @+key:String -> @st:0x14e48621ef66156b0eb652524b8594d4/retry.State -> IO(Ran(A))

template trip source · line 204 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 208 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 221 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 230 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 238 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @r:Runner<A> -> @t:0xea5958c4b1eace15f18f0607b2d582f0/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 248 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @y:Ran(A) -> @t:0xea5958c4b1eace15f18f0607b2d582f0/queue.Ticket<A> -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))

template claim.pick source · line 256 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+left:Nat -> @+now:Nat -> @k:0x08e52f309002d32aa01c2d0663a904d6/model.Pick<A> -> @j:Log -> @s:0x08e52f309002d32aa01c2d0663a904d6/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 268 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 281 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @+op:0x08e52f309002d32aa01c2d0663a904d6/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 293 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 333 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 341 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @t:Pair(Maybe<&1, Flight<A>>, List<&1, Flight<A>>) -> @+o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @+now:Nat -> @+rnd:Nat -> @j:Log -> @s:0x08e52f309002d32aa01c2d0663a904d6/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 348 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 386 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 485 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @ok:Bool -> @j:0xb9c6a8952912eecb2aa814630cbfa908/journal.Journal -> @+max:U32 -> @+path:String -> @+limit:U32 -> @+base:U32 -> @s:0x08e52f309002d32aa01c2d0663a904d6/model.State<A> -> IO(Pair(Log, Out(Unit)))

template compact source · line 501 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 519 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @due:Bool -> @+b:Bool -> @r:Runner<A> -> IO(Pair(Runner<A>, Out(Bool)))

template tick.size source · line 528 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @r:Runner<A> -> @+b:Bool -> IO(Pair(Runner<A>, Out(Bool)))

template tick.grown source · line 535 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 568 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 583 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 596 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 607 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 630 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 646 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 653 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 660 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 670 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 681 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 692 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/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 704 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @ts:List<&2, 0xea5958c4b1eace15f18f0607b2d582f0/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 776 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @x:Out(Pair(0xb9c6a8952912eecb2aa814630cbfa908/journal.Journal, Maybe<&2, 0x08e52f309002d32aa01c2d0663a904d6/model.State<A>>)) -> @+max:U32 -> @path:String -> @+limit:U32 -> @c:Config -> @+capacity:Nat -> IO(Out(Runner<A>))

template open source · line 796 · raw

@-A:Data -> @-penc:(@_:A -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @-pdec:(@_:0xec25e4adfb02e59e4b817801115988ee/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.

template inspect source · line 807 · raw

@-A:Data -> @-pdec:(@_:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Maybe<&2, A>) -> @path:String -> @max:U32 -> @limit:U32 -> IO(Out(0x08e52f309002d32aa01c2d0663a904d6/inspect.Inspection<A>))

Reads without mutation or crash recovery. A torn suffix retains its committed prefix.