runner.bend relies on unsafe/foreign
raw source on the hub · import bend-kit-runner@0.1.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 0x49814d83de8f70993a43e1002be29ecd/bytes.bend as Bytes import bend-kit-journal@0.1.0.0/journal.bend as J import bend-kit-scheduler@0.2.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.1.3.0/time.bend as Time import bend-kit-collections@0.1.2.0/heap.bend as H import bend-kit-collections@0.1.2.0/omap.bend as O
Types
type Op source · line 16 · 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.
Enqueue@-A:Data -> @deadline:Nat -> @payload:A -> Op<A>
Select@-A:Data -> @now:Nat -> Op<A>
Complete@-A:Data -> @id:Nat -> Op<A>
Cancel@-A:Data -> @id:Nat -> Op<A>
Requeue@-A:Data -> @id:Nat -> @deadline:Nat -> Op<A>
Defer@-A:Data -> @id:Nat -> @deadline:Nat -> Op<A>
type Try source · line 25 · raw
Data
The failed attempts of a ticket, and its first deadline, from which the policy deadline counts.
Try@fails:Nat -> @start:Nat -> Try
type State source · line 33 · raw
@-A:Data -> Data
The durable state: the queue and the tries.
State@-A:Data -> @queue:0x5f14902bda92dea7eab2b8da03967100/queue.State<A> -> @tries:Tries -> State<A>
type Pick source · line 118 · 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.
Picked@-A:Data -> @pool:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @ticket:0x5f14902bda92dea7eab2b8da03967100/queue.Ticket<A> -> @grant:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> Pick<A>
Idle@-A:Data -> @pool:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> Pick<A>
type Config source · line 304 · raw
Data
policy: retry's policy for each ticket. circuit: the breaker of each target. idle: ms that drain waits when no attempt started.
Config@policy:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Policy -> @circuit:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Circuit -> @idle:U32 -> Config
type Runner source · line 308 · raw
@-A:Data -> Type
An open runner. Its journal holds every op that made state; its pool bounds the attempts that run at once.
Runner@-A:Data -> @journal:0x801060290904d418c14ffa544e867442/journal.Journal -> @state:State<A> -> @pool:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @breakers:Map<&2, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker> -> @config:Config -> Runner<A>
type Flight source · line 312 · 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.
Flight@-A:Data -> @ticket:0x5f14902bda92dea7eab2b8da03967100/queue.Ticket<A> -> @grant:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @budget:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Budget -> @target:String -> @chan:Chan(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome) -> Flight<A>
Definitions
def Tries source · line 29 · raw
Data
A Try for each ticket that is not yet complete or cancelled, by ticket id.
def new source · line 36 · raw
@-A:Data -> State<A>
def queue source · line 39 · raw
@-A:Data -> @s:State<A> -> 0x5f14902bda92dea7eab2b8da03967100/queue.State<A>
def tries source · line 43 · raw
@-A:Data -> @s:State<A> -> Tries
def tries.drop source · line 49 · raw
@ts:Tries -> @+i:Nat -> Tries
def tries.get source · line 52 · raw
@ts:Tries -> @+i:Nat -> Maybe<&2, Try>
def tries.bump.got source · line 55 · raw
@m:Maybe<&2, Try> -> @ts:Tries -> @+i:Nat -> Tries
def tries.bump source · line 62 · raw
@+ts:Tries -> @+i:Nat -> Tries
def step.enqueued source · line 67 · raw
@-A:Data -> @r:Pair(0x5f14902bda92dea7eab2b8da03967100/queue.State<A>, Nat) -> @ts:Tries -> @d:Nat -> State<A>
def step.selected source · line 71 · raw
@-A:Data -> @r:Pair(0x5f14902bda92dea7eab2b8da03967100/queue.State<A>, Maybe<&2, 0x5f14902bda92dea7eab2b8da03967100/queue.Ticket<A>>) -> @ts:Tries -> State<A>
def step.requeued source · line 75 · raw
@-A:Data -> @r:Pair(0x5f14902bda92dea7eab2b8da03967100/queue.State<A>, Bool) -> @ts:Tries -> State<A>
def step.completed source · line 80 · raw
@-A:Data -> @r:Pair(0x5f14902bda92dea7eab2b8da03967100/queue.State<A>, Maybe<&2, 0x5f14902bda92dea7eab2b8da03967100/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 122 · raw
@-A:Data -> @r:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Reserve -> @t:0x5f14902bda92dea7eab2b8da03967100/queue.Ticket<A> -> Pick<A>
def pick.due source · line 129 · raw
@-A:Data -> @m:Maybe<&2, 0x5f14902bda92dea7eab2b8da03967100/queue.Ticket<A>> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> Pick<A>
def pick.sel source · line 136 · raw
@-A:Data -> @r:Pair(0x5f14902bda92dea7eab2b8da03967100/queue.State<A>, Maybe<&2, 0x5f14902bda92dea7eab2b8da03967100/queue.Ticket<A>>) -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> Pick<A>
def budget.of source · line 148 · 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 157 · raw
@p:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Policy -> @t:Maybe<&2, Try> -> 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Budget
def fails source · line 162 · raw
@t:Maybe<&2, Try> -> Nat
The failures so far: the index of the next retry.
def after.plan source · line 169 · raw
@-A:Data -> @pl:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Plan -> @+id:Nat -> @+now:Nat -> Op<A>
def after source · line 177 · 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 181 · raw
@br:0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker -> @+now:Nat -> Nat
When an open breaker lets attempts start again.
def held source · line 193 · 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 204 · raw
Nat
def put.u64 source · line 208 · raw
@b:0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes -> @+at:U32 -> @+n:Nat -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes
Nat fields hold values under 2^64.
def head source · line 211 · raw
@+tag:U32 -> @+a:Nat -> @+c:Nat -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes
def get.field source · line 229 · raw
@m:Maybe<&2, U32> -> U32
def get.u32 source · line 236 · raw
@r:Pair(0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes, U32)
def get.hi source · line 240 · raw
@+lo:U32 -> @r:Pair(0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes, Nat)
def get.lo source · line 244 · raw
@+at:U32 -> @r:Pair(0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes, Nat)
def get.u64 source · line 249 · raw
@b:0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes -> @+at:U32 -> Pair(0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes, Nat)
def decode.small source · line 252 · raw
@-A:Data -> @ok:Bool -> @+tag:U32 -> @+a:Nat -> @+c:Nat -> Maybe<&2, Op<A>>
def decode.payload source · line 263 · raw
@-A:Data -> @m:Maybe<&2, A> -> @+d:Nat -> Maybe<&2, Op<A>>
def Out source · line 315 · raw
@-X:Type -> Type
def Claimed source · line 318 · raw
@-A:Data -> Type
def Ran source · line 321 · raw
@-A:Data -> Type
def clock source · line 325 · raw
IO(Nat)
Wall-clock ms since the Unix epoch. Deadlines must keep their meaning across a restart.
def first source · line 330 · raw
@a:Out(Unit) -> @b:Out(Unit) -> Out(Unit)
def release.got source · line 353 · raw
@-A:Data -> @x:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Release -> @j:0x801060290904d418c14ffa544e867442/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 360 · raw
@-A:Data -> @r:Runner<A> -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> Runner<A>
def claim.held source · line 364 · 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 428 · 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 446 · raw
@r:Out(U32) -> Nat
def empty.heap source · line 469 · raw
@-A:Data -> @h:0xd2d968d969a26029a632a3347c989456/heap.Heap<0x5f14902bda92dea7eab2b8da03967100/queue.Ticket<A>> -> Bool
def empty.list source · line 476 · raw
@-A:Data -> @xs:List<&2, 0x5f14902bda92dea7eab2b8da03967100/queue.Ticket<A>> -> Bool
def idle source · line 484 · raw
@-A:Data -> @s:State<A> -> Bool
No ticket is pending or running.
def pending source · line 488 · raw
@-A:Data -> @s:State<A> -> Nat
def tick.ran source · line 492 · raw
@e:Out(Unit) -> @b:Bool -> Out(Bool)
def tick.done source · line 499 · raw
@-A:Data -> @y:Ran(A) -> Pair(Runner<A>, Out(Bool))
def drain.ticked source · line 525 · 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 558 · 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 572 · raw
@-A:Data -> @y:Ran(A) -> IO(Out(Runner<A>))
def enqueue.done source · line 606 · raw
@-A:Data -> @+id:Nat -> @y:Ran(A) -> Pair(Runner<A>, Out(Nat))
def state source · line 625 · raw
@-A:Data -> @r:Runner<A> -> Pair(Runner<A>, State<A>)
The runner back, and a copy of its state.
def close source · line 629 · raw
@-A:Data -> @r:Runner<A> -> IO(Unit)
Templates
template step source · line 85 · 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 100 · raw
@-A:Data -> @m:Maybe<&2, Op<A>> -> @s:State<A> -> Maybe<&2, State<A>>
template apply source · line 108 · 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 141 · 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 214 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes) -> @op:Op<A> -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes
template decode.c source · line 270 · raw
@-A:Data -> @-pdec:(@_:0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes -> Maybe<&2, A>) -> @+tag:U32 -> @+len:U32 -> @+a:Nat -> @r:Pair(0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes, Nat) -> Maybe<&2, Op<A>>
template decode.kind source · line 274 · raw
@-A:Data -> @-pdec:(@_:0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes -> Maybe<&2, A>) -> @enq:Bool -> @+tag:U32 -> @+len:U32 -> @+a:Nat -> @b:0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes -> Maybe<&2, Op<A>>
template decode.a source · line 281 · raw
@-A:Data -> @-pdec:(@_:0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes -> Maybe<&2, A>) -> @+tag:U32 -> @+len:U32 -> @r:Pair(0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes, Nat) -> Maybe<&2, Op<A>>
template decode.tag source · line 285 · raw
@-A:Data -> @-pdec:(@_:0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes -> Maybe<&2, A>) -> @+len:U32 -> @r:Pair(0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes, U32) -> Maybe<&2, Op<A>>
template decode.len source · line 289 · raw
@-A:Data -> @-pdec:(@_:0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes -> Maybe<&2, A>) -> @ok:Bool -> @+len:U32 -> @b:0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes -> Maybe<&2, Op<A>>
template decode source · line 297 · raw
@-A:Data -> @-pdec:(@_:0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes -> Maybe<&2, A>) -> @b:0x49814d83de8f70993a43e1002be29ecd/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 337 · raw
@-A:Data -> @x:Pair(0x801060290904d418c14ffa544e867442/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 346 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/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 371 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/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:0x801060290904d418c14ffa544e867442/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 384 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @+now:Nat -> @got:Pair(Map<&2, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker>, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker) -> @+key:String -> @j:0x801060290904d418c14ffa544e867442/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 392 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @+now:Nat -> @r:Runner<A> -> @t:0x5f14902bda92dea7eab2b8da03967100/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 400 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @+now:Nat -> @y:Ran(A) -> @t:0x5f14902bda92dea7eab2b8da03967100/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 408 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Outcome)) -> @+now:Nat -> @k:Pick<A> -> @j:0x801060290904d418c14ffa544e867442/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 419 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/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 432 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes) -> @+failed:Bool -> @+key:String -> @+now:Nat -> @got:Pair(Map<&2, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker>, 0x12d3bb9bb57264f1d5e2fcf763dbe13b/retry.Breaker) -> @+op:Op<A> -> @j:0x801060290904d418c14ffa544e867442/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 439 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/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 454 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/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 462 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes) -> @fs:List<&1, Flight<A>> -> @r:Runner<A> -> @err:Out(Unit) -> IO(Ran(A))
template tick.settle source · line 503 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes) -> @c:Claimed(A) -> IO(Pair(Runner<A>, Out(Bool)))
template tick.at source · line 512 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/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 520 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/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 536 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/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 549 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/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 563 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes) -> @ts:List<&2, 0x5f14902bda92dea7eab2b8da03967100/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 581 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes) -> @x:Out(Pair(0x801060290904d418c14ffa544e867442/journal.Journal, Maybe<&2, State<A>>)) -> @c:Config -> @+capacity:Nat -> IO(Out(Runner<A>))
template replay.step source · line 595 · raw
@-A:Data -> @-pdec:(@_:0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes -> Maybe<&2, A>) -> @acc:Maybe<&2, State<A>> -> @b:0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes -> Maybe<&2, State<A>>
template open source · line 601 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes) -> @-pdec:(@_:0x49814d83de8f70993a43e1002be29ecd/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 614 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/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 621 · raw
@-A:Data -> @-penc:(@_:A -> 0x49814d83de8f70993a43e1002be29ecd/bytes.Bytes) -> @r:Runner<A> -> @+id:Nat -> IO(Ran(A))
Cancels ticket id. A running attempt finishes, but its ticket is never selected again.