poll.bend relies on unsafe/foreign
raw source on the hub · import cswap-bend-cli@0.1.0.0/poll.bend as MPoll
5 imports
import Base import ./json.bend as Json import ./clock.bend as Clock import ./policy/usage.bend as PUsage import ./policy/types.bend as PT
Types
type Win source · line 124 · raw
Data
One usage window: its percentage (tenths) and when it resets.
Win@pct:U32 -> @reset:Maybe<&2, U32> -> Win
type Sched source · line 159 · raw
Data
When to poll next and the interval it came from.
Sched@next:U32 -> @interval:U32 -> Sched
Definitions
def serve_ttl source · line 13 · raw
U32
def decision_trust source · line 16 · raw
U32
def trust_ceiling source · line 19 · raw
U32
def rate_limit_trust_ceiling source · line 22 · raw
U32
def claim_ttl source · line 25 · raw
U32
def min_interval source · line 28 · raw
U32
def urgent_interval source · line 31 · raw
U32
def active_ceiling source · line 34 · raw
U32
def candidate_default source · line 37 · raw
U32
def candidate_ceiling source · line 40 · raw
U32
def exhausted_interval source · line 43 · raw
U32
def reset_slack source · line 46 · raw
U32
def recent_429_window source · line 49 · raw
U32
def post_429_min source · line 52 · raw
U32
def post_429_cap source · line 55 · raw
U32
def edge_backoff source · line 58 · raw
U32
def backoff_base source · line 61 · raw
U32
def backoff_cap source · line 64 · raw
U32
def retry_margin source · line 67 · raw
U32
def retry_floor_cap source · line 70 · raw
U32
def escalation_margin source · line 73 · raw
U32
def min_u source · line 76 · raw
@+a:U32 -> @+b:U32 -> U32
def max_u source · line 79 · raw
@+a:U32 -> @+b:U32 -> U32
def sub0 source · line 83 · raw
@+a:U32 -> @+b:U32 -> U32
a - b, floored at 0.
def absdiff source · line 86 · raw
@+a:U32 -> @+b:U32 -> U32
def tenths.mk source · line 89 · raw
@+i:String -> @+f:String -> Maybe<&2, U32>
def tenths.pick source · line 96 · raw
@ok:Bool -> @+i:String -> @+f:String -> Maybe<&2, U32>
def tenths.parts source · line 103 · raw
@ps:List<&2, String> -> Maybe<&2, U32>
def tenths source · line 113 · raw
@s:String -> Maybe<&2, U32>
42.5 -> 425, rounded to a tenth; None for anything but a plain decimal.
def tenths.json source · line 116 · raw
@j:0x0717344745a30ebad1f19045228e8f18/json.Json -> Maybe<&2, U32>
def win.parse source · line 127 · raw
@m:Maybe<&2, String> -> Maybe<&2, U32>
def win.reset source · line 134 · raw
@+w:0x0717344745a30ebad1f19045228e8f18/json.Json -> Maybe<&2, U32>
def min_acc source · line 136 · raw
@acc:Maybe<&2, U32> -> @+p:U32 -> Maybe<&2, U32>
def any.step source · line 143 · raw
@r:Maybe<&2, U32> -> @acc:Maybe<&2, U32> -> Maybe<&2, U32>
def earliest_reset source · line 151 · raw
@ws:List<&2, Win> -> @acc:Maybe<&2, U32> -> Maybe<&2, U32>
The earliest reset of any relevant window (past or future): trust ends there.
def interval.moving source · line 162 · raw
@+base:U32 -> U32
def interval.still source · line 165 · raw
@+base:U32 -> @+ceil:U32 -> U32
def interval.base source · line 169 · raw
@prev:Maybe<&2, U32> -> @+dflt:U32 -> U32
Default for unknown utilization, halve on movement, back off x1.5 otherwise.
def interval.pick source · line 176 · raw
@known:Bool -> @moving:Bool -> @+dflt:U32 -> @+base:U32 -> @+ceil:U32 -> U32
def is_moving source · line 185 · raw
@prev:Maybe<&2, U32> -> @new:Maybe<&2, U32> -> Bool
def is_known source · line 192 · raw
@prev:Maybe<&2, U32> -> @new:Maybe<&2, U32> -> Bool
def new_ge source · line 195 · raw
@new:Maybe<&2, U32> -> @+floor:U32 -> Bool
def exhausted source · line 202 · raw
@new:Maybe<&2, U32> -> Bool
def plan.r429 source · line 209 · raw
@recent:Bool -> @+base:U32 -> @+i:U32 -> U32
def plan.exh source · line 212 · raw
@ex:Bool -> @+i:U32 -> U32
def plan.interval source · line 215 · raw
@+i0:U32 -> @+urgent:Bool -> @+recent:Bool -> @+base:U32 -> @+ex:Bool -> U32
def plan.cap source · line 218 · raw
@+next:U32 -> @r:Maybe<&2, U32> -> U32
def keep.m source · line 225 · raw
@ok:Bool -> @m:Maybe<&2, U32> -> Maybe<&2, U32>
def plan.reset.pick source · line 232 · raw
@ex:Bool -> @lim:Maybe<&2, U32> -> @fut:Maybe<&2, U32> -> @+now:U32 -> Maybe<&2, U32>
def plan.fin source · line 241 · raw
@+now:U32 -> @+interval:U32 -> @r:Maybe<&2, U32> -> Sched
def nat_maybe source · line 244 · raw
@m:Maybe<&2, U32> -> Maybe<&2, Nat>
def reset_nat source · line 251 · raw
@+w:0x0717344745a30ebad1f19045228e8f18/json.Json -> Maybe<&2, Nat>
def centi source · line 254 · raw
@m:Maybe<&2, U32> -> Maybe<&2, Nat>
def pct_centi source · line 261 · raw
@+w:0x0717344745a30ebad1f19045228e8f18/json.Json -> Maybe<&2, Nat>
def scoped.mk source · line 264 · raw
@n:Maybe<&2, String> -> @p:Maybe<&2, Nat> -> @r:Maybe<&2, Nat> -> Maybe<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Scoped>
def scoped.item source · line 271 · raw
@+w:0x0717344745a30ebad1f19045228e8f18/json.Json -> Maybe<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Scoped>
def scoped.cons source · line 274 · raw
@m:Maybe<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Scoped> -> @rest:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Scoped> -> List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Scoped>
def scoped.all source · line 281 · raw
@ws:List<&2, 0x0717344745a30ebad1f19045228e8f18/json.Json> -> List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Scoped>
def window_of source · line 288 · raw
@+u:0x0717344745a30ebad1f19045228e8f18/json.Json -> @+k:String -> 0x0717344745a30ebad1f19045228e8f18/json.Json
def policy_usage source · line 292 · raw
@+u:0x0717344745a30ebad1f19045228e8f18/json.Json -> 0x0717344745a30ebad1f19045228e8f18/policy/types.Usage
The policy core's view of a usage object (centi-percent windows).
def maybe_u32 source · line 295 · raw
@m:Maybe<&2, Nat> -> Maybe<&2, U32>
def win.back source · line 302 · raw
@ws:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Win> -> List<&2, Win>
def relevant source · line 311 · raw
@+usage:0x0717344745a30ebad1f19045228e8f18/json.Json -> @+models:List<&2, String> -> List<&2, Win>
Every window that gates an account (5h, 7d, and the scoped windows of the
named models): policy's windows, back as tenths for the planner.
def future.pick source · line 314 · raw
@ok:Bool -> @+x:U32 -> @acc:Maybe<&2, U32> -> Maybe<&2, U32>
def future.step source · line 321 · raw
@r:Maybe<&2, U32> -> @+now:U32 -> @acc:Maybe<&2, U32> -> Maybe<&2, U32>
def earliest_future source · line 328 · raw
@ws:List<&2, Win> -> @+now:U32 -> @acc:Maybe<&2, U32> -> Maybe<&2, U32>
def max_acc source · line 335 · raw
@acc:Maybe<&2, U32> -> @+p:U32 -> Maybe<&2, U32>
def limiting.step source · line 342 · raw
@full:Bool -> @r:Maybe<&2, U32> -> @acc:Maybe<&2, U32> -> Maybe<&2, U32>
def limiting_reset source · line 349 · raw
@ws:List<&2, Win> -> @acc:Maybe<&2, U32> -> Maybe<&2, U32>
def plan.go source · line 356 · raw
@+usage:0x0717344745a30ebad1f19045228e8f18/json.Json -> @+models:List<&2, String> -> @+now:U32 -> @+interval:U32 -> @+ex:Bool -> Sched
def plan.with source · line 359 · raw
@+base:U32 -> @+known:Bool -> @+moving:Bool -> @+ex:Bool -> @+in_band:Bool -> @+usage:0x0717344745a30ebad1f19045228e8f18/json.Json -> @+active:Bool -> @+models:List<&2, String> -> @+recent:Bool -> @+now:U32 -> @+ceil:U32 -> @+dflt:U32 -> Sched
def dflt_of source · line 364 · raw
@active:Bool -> U32
def ceil_of source · line 367 · raw
@active:Bool -> U32
def plan.start source · line 370 · raw
@prev_interval:Maybe<&2, U32> -> @+prev:Maybe<&2, U32> -> @+new:Maybe<&2, U32> -> @+usage:0x0717344745a30ebad1f19045228e8f18/json.Json -> @+active:Bool -> @+threshold:U32 -> @+models:List<&2, String> -> @recent:Bool -> @+now:U32 -> Sched
def max_pct source · line 374 · raw
@ws:List<&2, Win> -> @acc:Maybe<&2, U32> -> Maybe<&2, U32>
def binding source · line 381 · raw
@usage:0x0717344745a30ebad1f19045228e8f18/json.Json -> @models:List<&2, String> -> Maybe<&2, U32>
def plan_after_fetch source · line 386 · raw
@prev_interval:Maybe<&2, U32> -> @prev_usage:0x0717344745a30ebad1f19045228e8f18/json.Json -> @+new_usage:0x0717344745a30ebad1f19045228e8f18/json.Json -> @is_active:Bool -> @+threshold:U32 -> @+models:List<&2, String> -> @recent_429:Bool -> @+now:U32 -> Sched
plan_after_fetch (no jitter): threshold in tenths, models the scoped
names that gate the account, times in unix seconds.