~/bend-docscommunity

runner.bend relies on unsafe/foreign

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

9 imports
import Base
import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes
import bend-kit-journal@0.2.0.0/journal.bend as J
import bend-kit-scheduler@0.3.0.0/queue.bend as Q
import bend-kit-resources@0.1.0.0/resources.bend as Res
import bend-kit-retry@0.1.0.0/retry.bend as Retry
import bend-kit-time@0.2.0.0/time.bend as Time
import bend-kit-collections@0.1.3.0/heap.bend as H
import bend-kit-collections@0.1.3.0/omap.bend as O

Types

type Op source · line 15 · raw

@-A:Data -> Data

One queue transition. Each one is one journal record, appended before the state changes. Select: the queue's select at now. Replay runs it at the same now, so it takes the same ticket. Requeue: the attempt failed; it counts one failure. Defer: the breaker held the ticket back; no attempt ran.

type Try source · line 24 · raw

Data

The failed attempts of a ticket, and its first deadline, from which the policy deadline counts.

type State source · line 32 · raw

@-A:Data -> Data

The durable state: the queue and the tries.

type Pick source · line 117 · raw

@-A:Data -> Type

Picked: a due ticket and one unit of the pool for it. Idle: no due ticket, or no free unit; the pool is unchanged.

type Config source · line 303 · raw

Data

policy: retry's policy for each ticket. circuit: the breaker of each target. idle: ms that drain waits when no attempt started.

type Runner source · line 307 · raw

@-A:Data -> Type

An open runner. Its journal holds every op that made state; its pool bounds the attempts that run at once.

type Flight source · line 311 · raw

@-A:Data -> Type

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

Definitions

def Tries source · line 28 · raw

Data

A Try for each ticket that is not yet complete or cancelled, by ticket id.

def new source · line 35 · raw

@-A:Data -> State<A>

def queue source · line 38 · raw

@-A:Data -> @s:State<A> -> 0x355167368b46de39ede21286fd4d9a78/queue.State<A>

def tries source · line 42 · raw

@-A:Data -> @s:State<A> -> Tries

def tries.drop source · line 48 · raw

@ts:Tries -> @+i:Nat -> Tries

def tries.get source · line 51 · raw

@ts:Tries -> @+i:Nat -> Maybe<&2, Try>

def tries.bump.got source · line 54 · raw

@m:Maybe<&2, Try> -> @ts:Tries -> @+i:Nat -> Tries

def tries.bump source · line 61 · raw

@+ts:Tries -> @+i:Nat -> Tries

def step.enqueued source · line 66 · raw

@-A:Data -> @r:Pair(0x355167368b46de39ede21286fd4d9a78/queue.State<A>, Nat) -> @ts:Tries -> @d:Nat -> State<A>

def step.selected source · line 70 · raw

@-A:Data -> @r:Pair(0x355167368b46de39ede21286fd4d9a78/queue.State<A>, Maybe<&2, 0x355167368b46de39ede21286fd4d9a78/queue.Ticket<A>>) -> @ts:Tries -> State<A>

def step.requeued source · line 74 · raw

@-A:Data -> @r:Pair(0x355167368b46de39ede21286fd4d9a78/queue.State<A>, Bool) -> @ts:Tries -> State<A>

def step.completed source · line 79 · raw

@-A:Data -> @r:Pair(0x355167368b46de39ede21286fd4d9a78/queue.State<A>, Maybe<&2, 0x355167368b46de39ede21286fd4d9a78/queue.Ticket<A>>) -> @ts:Tries -> State<A>

Complete takes the ticket from the running list only: O(running), not O(pending).

def pick.took source · line 121 · raw

@-A:Data -> @r:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Reserve -> @t:0x355167368b46de39ede21286fd4d9a78/queue.Ticket<A> -> Pick<A>

def pick.due source · line 128 · raw

@-A:Data -> @m:Maybe<&2, 0x355167368b46de39ede21286fd4d9a78/queue.Ticket<A>> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> Pick<A>

def pick.sel source · line 135 · raw

@-A:Data -> @r:Pair(0x355167368b46de39ede21286fd4d9a78/queue.State<A>, Maybe<&2, 0x355167368b46de39ede21286fd4d9a78/queue.Ticket<A>>) -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> Pick<A>

def budget.of source · line 147 · raw

@+attempts:Nat -> @t:Maybe<&2, Try> -> @d:Maybe<&2, Nat> -> 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Budget

The budget left for ticket i: the policy's attempts less its failures, until its start plus the policy deadline.

def budget source · line 156 · raw

@p:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Policy -> @t:Maybe<&2, Try> -> 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Budget

def fails source · line 161 · raw

@t:Maybe<&2, Try> -> Nat

The failures so far: the index of the next retry.

def after.plan source · line 168 · raw

@-A:Data -> @pl:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Plan -> @+id:Nat -> @+now:Nat -> Op<A>

def after source · line 176 · raw

@-A:Data -> @o:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome -> @p:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Policy -> @b:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Budget -> @+id:Nat -> @+n:Nat -> @+now:Nat -> @+r:Nat -> Op<A>

The record after an attempt of ticket id ends at now with o: requeue at now plus retry's wait, or complete.

def until source · line 180 · raw

@br:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker -> @+now:Nat -> Nat

When an open breaker lets attempts start again.

def held source · line 192 · raw

@-A:Data -> @why:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Deny -> @br:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker -> @+id:Nat -> @+now:Nat -> Op<A>

The record for a ticket that admit refused: Defer to when the breaker may admit, or Complete when its budget is spent or late.

def W source · line 203 · raw

Nat

def put.u64 source · line 207 · raw

@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+at:U32 -> @+n:Nat -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes

Nat fields hold values under 2^64.

def get.field source · line 228 · raw

@m:Maybe<&2, U32> -> U32

def get.u32 source · line 235 · raw

@r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, U32)

def get.hi source · line 239 · raw

@+lo:U32 -> @r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Nat)

def get.lo source · line 243 · raw

@+at:U32 -> @r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Nat)

def get.u64 source · line 248 · raw

@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+at:U32 -> Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Nat)

def decode.small source · line 251 · raw

@-A:Data -> @ok:Bool -> @+tag:U32 -> @+a:Nat -> @+c:Nat -> Maybe<&2, Op<A>>

def decode.payload source · line 262 · raw

@-A:Data -> @m:Maybe<&2, A> -> @+d:Nat -> Maybe<&2, Op<A>>

def Out source · line 314 · raw

@-X:Type -> Type

def Claimed source · line 317 · raw

@-A:Data -> Type

def Ran source · line 320 · raw

@-A:Data -> Type

def clock source · line 324 · raw

IO(Nat)

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

def first source · line 329 · raw

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

def release.got source · line 352 · raw

@-A:Data -> @x:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Release -> @j:0x228909d5e58383594fb8ed54c2ddc150/journal.Journal -> @s:State<A> -> @bs:Map<&2, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker> -> @c:Config -> Runner<A>

A grant of this runner's pool always fits it, so Kept does not happen.

def release source · line 359 · raw

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

def claim.held source · line 363 · raw

@-A:Data -> @y:Ran(A) -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @fs:List<&1, Flight<A>> -> @next:(@_:Runner<A> -> @_:List<&1, Flight<A>> -> IO(Claimed(A))) -> IO(Claimed(A))

def settle.done source · line 427 · raw

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

def random source · line 445 · raw

@r:Out(U32) -> Nat

def empty.heap source · line 468 · raw

@-A:Data -> @h:0x3247b353c72fc13d6f940252da321399/heap.Heap<0x355167368b46de39ede21286fd4d9a78/queue.Ticket<A>> -> Bool

def empty.list source · line 475 · raw

@-A:Data -> @xs:List<&2, 0x355167368b46de39ede21286fd4d9a78/queue.Ticket<A>> -> Bool

def idle source · line 483 · raw

@-A:Data -> @s:State<A> -> Bool

No ticket is pending or running.

def pending source · line 487 · raw

@-A:Data -> @s:State<A> -> Nat

def tick.ran source · line 491 · raw

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

def tick.done source · line 498 · raw

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

def drain.ticked source · line 524 · raw

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

def orphans.next source · line 557 · raw

@-A:Data -> @y:Ran(A) -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Ran(A))) -> IO(Ran(A))

def open.done source · line 571 · raw

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

def enqueue.done source · line 605 · raw

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

def state source · line 624 · raw

@-A:Data -> @r:Runner<A> -> Pair(Runner<A>, State<A>)

The runner back, and a copy of its state.

def close source · line 628 · raw

@-A:Data -> @r:Runner<A> -> IO(Unit)

Templates

template step source · line 84 · raw

@-A:Data -> @s:State<A> -> @op:Op<A> -> State<A>

The state after op. Live and replay both run it, so they agree.

template apply.op source · line 99 · raw

@-A:Data -> @m:Maybe<&2, Op<A>> -> @s:State<A> -> Maybe<&2, State<A>>

template apply source · line 107 · raw

@-A:Data -> @-R:Type -> @-dec:(@_:R -> Maybe<&2, Op<A>>) -> @acc:Maybe<&2, State<A>> -> @r:R -> Maybe<&2, State<A>>

Folds one record into the replayed state. A record that does not decode ends the replay with None.

template pick source · line 140 · raw

@-A:Data -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @s:State<A> -> @now:Nat -> Pick<A>

The ticket that Select{now} takes, with one unit of p, when there is a ticket due and a unit free.

template encode source · line 213 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @op:Op<A> -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes

template decode.c source · line 269 · raw

@-A:Data -> @-pdec:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Maybe<&2, A>) -> @+tag:U32 -> @+len:U32 -> @+a:Nat -> @r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Nat) -> Maybe<&2, Op<A>>

template decode.kind source · line 273 · raw

@-A:Data -> @-pdec:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Maybe<&2, A>) -> @enq:Bool -> @+tag:U32 -> @+len:U32 -> @+a:Nat -> @b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Maybe<&2, Op<A>>

template decode.a source · line 280 · raw

@-A:Data -> @-pdec:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Maybe<&2, A>) -> @+tag:U32 -> @+len:U32 -> @r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Nat) -> Maybe<&2, Op<A>>

template decode.tag source · line 284 · raw

@-A:Data -> @-pdec:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Maybe<&2, A>) -> @+len:U32 -> @r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, U32) -> Maybe<&2, Op<A>>

template decode.len source · line 288 · raw

@-A:Data -> @-pdec:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Maybe<&2, A>) -> @ok:Bool -> @+len:U32 -> @b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Maybe<&2, Op<A>>

template decode source · line 296 · raw

@-A:Data -> @-pdec:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Maybe<&2, A>) -> @b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Maybe<&2, Op<A>>

The op of a record, or None when it is not one that encode writes.

template commit.done source · line 336 · raw

@-A:Data -> @x:Pair(0x228909d5e58383594fb8ed54c2ddc150/journal.Journal, Out(Unit)) -> @s:State<A> -> @+op:Op<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @bs:Map<&2, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker> -> @c:Config -> Ran(A)

template commit source · line 345 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @r:Runner<A> -> @+op: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 claim.go source · line 370 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @+now:Nat -> @a:Pair(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker, Pair(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Budget, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Gate)) -> @+key:String -> @j:0x228909d5e58383594fb8ed54c2ddc150/journal.Journal -> @s:State<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @bs:Map<&2, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker> -> @c:Config -> @+id:Nat -> @d:Nat -> @+x:A -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @fs:List<&1, Flight<A>> -> @next:(@_:Runner<A> -> @_:List<&1, Flight<A>> -> IO(Claimed(A))) -> IO(Claimed(A))

template claim.gate source · line 383 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @+now:Nat -> @got:Pair(Map<&2, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker>, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker) -> @+key:String -> @j:0x228909d5e58383594fb8ed54c2ddc150/journal.Journal -> @+s:State<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @+c:Config -> @+id:Nat -> @d:Nat -> @+x:A -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @fs:List<&1, Flight<A>> -> @next:(@_:Runner<A> -> @_:List<&1, Flight<A>> -> IO(Claimed(A))) -> IO(Claimed(A))

template claim.admit source · line 391 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @+now:Nat -> @r:Runner<A> -> @t:0x355167368b46de39ede21286fd4d9a78/queue.Ticket<A> -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @fs:List<&1, Flight<A>> -> @next:(@_:Runner<A> -> @_:List<&1, Flight<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 399 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @+now:Nat -> @y:Ran(A) -> @t:0x355167368b46de39ede21286fd4d9a78/queue.Ticket<A> -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @fs:List<&1, Flight<A>> -> @next:(@_:Runner<A> -> @_:List<&1, Flight<A>> -> IO(Claimed(A))) -> IO(Claimed(A))

template claim.pick source · line 407 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @+now:Nat -> @k:Pick<A> -> @j:0x228909d5e58383594fb8ed54c2ddc150/journal.Journal -> @s:State<A> -> @bs:Map<&2, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker> -> @c:Config -> @fs:List<&1, Flight<A>> -> @next:(@_:Runner<A> -> @_:List<&1, Flight<A>> -> IO(Claimed(A))) -> IO(Claimed(A))

template claim source · line 418 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @fuel:Nat -> @+now:Nat -> @r:Runner<A> -> @fs:List<&1, Flight<A>> -> IO(Claimed(A))

Starts an attempt for each due ticket while the pool has a free unit. fuel bounds the tickets taken.

template settle.br source · line 431 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @+failed:Bool -> @+key:String -> @+now:Nat -> @got:Pair(Map<&2, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker>, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker) -> @+op:Op<A> -> @j:0x228909d5e58383594fb8ed54c2ddc150/journal.Journal -> @s:State<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @c:Config -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Ran(A))) -> IO(Ran(A))

template settle.op source · line 438 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @+o:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome -> @b:0x12d3bb9bb57264f1d5e2fcf763dbe13b/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(Ran(A))) -> IO(Ran(A))

template settle.one source · line 453 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @r:Runner<A> -> @f:Flight<A> -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Ran(A))) -> IO(Ran(A))

Waits for the attempt, tells its target's breaker, appends Complete or Requeue, and returns its unit to the pool.

template settle source · line 461 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @fs:List<&1, Flight<A>> -> @r:Runner<A> -> @err:Out(Unit) -> IO(Ran(A))

template tick.settle source · line 502 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @c:Claimed(A) -> IO(Pair(Runner<A>, Out(Bool)))

template tick.at source · line 511 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @+now:Nat -> @r:Runner<A> -> IO(Pair(Runner<A>, Out(Bool)))

template tick source · line 519 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @r:Runner<A> -> IO(Pair(Runner<A>, Out(Bool)))

One round: start an attempt for each due ticket the pool admits, wait for them all, and record each outcome. Done{True} when an attempt ran. work runs on its own; target names the breaker that guards it.

template drain.if source · line 535 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @done:Bool -> @r:Runner<A> -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))

template drain source · line 548 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @fuel:Nat -> @r:Runner<A> -> IO(Ran(A))

Ticks until no ticket is pending or running. It waits idle ms after a round that started no attempt. Fails when fuel rounds leave work.

template orphans source · line 562 · raw

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

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @x:Out(Pair(0x228909d5e58383594fb8ed54c2ddc150/journal.Journal, Maybe<&2, State<A>>)) -> @c:Config -> @+capacity:Nat -> IO(Out(Runner<A>))

template replay.step source · line 594 · raw

@-A:Data -> @-pdec:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Maybe<&2, A>) -> @acc:Maybe<&2, State<A>> -> @b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Maybe<&2, State<A>>

template open source · line 600 · raw

@-A:Data -> @-penc:(@_:A -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @-pdec:(@_:0x185ae03c75e3e75be1171471f68b43cb/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 a record's octets; limit caps the journal file. Fails when the journal fails to open, or a committed record is not an op.

template enqueue source · line 613 · raw

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

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

Cancels ticket id. A running attempt finishes, but its ticket is never selected again.