gateway.bend checks
raw source on the hub · import bend-kit-gateway@0.5.0.0/gateway.bend as Gateway
A guarded read-through gateway: authorize, admit, serve from cache, and fetch on a miss. Source: https://github.com/paymog/bend-kit/tree/main/gateway
4 imports
import Base import bend-kit-authz@0.1.0.0/authz.bend as Az import bend-kit-resources@0.1.0.0/resources.bend as Res import bend-kit-cache@0.3.2.0/cache.bend as C
Types
type Gate source · line 9 · raw
Type
The shared state of one gateway. held joins every unit that the pool lent
and that no finish has given back yet.
Gate@pool:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @held:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @cache:0x874f22564c9f7947263463f6904f7d44/cache.Cache<String> -> Gate
type Pending source · line 13 · raw
Data
A fetch in flight, as copyable data, so it can cross to the request task and back.
Pending@key:String -> @gen:Nat -> @at:Nat -> Pending
type Upstream source · line 17 · raw
Data
What the upstream fetch did. Failed covers an upstream error, a spent budget, and an open breaker.
Fetched@found:0x874f22564c9f7947263463f6904f7d44/cache.Found<String> -> Upstream
FailedUpstream
type Begin source · line 21 · raw
Type
Denied@gate:Gate -> Begin
Busy@gate:Gate -> Begin
Fresh@gate:Gate -> @entry:0x874f22564c9f7947263463f6904f7d44/cache.Entry<String> -> Begin
Fetch@gate:Gate -> @pending:Pending -> Begin
type Finish source · line 27 · raw
Type
Settled@gate:Gate -> Finish
Unheld@gate:Gate -> Finish
Definitions
def new source · line 32 · raw
@+owner:Nat -> @capacity:Nat -> @policy:0x874f22564c9f7947263463f6904f7d44/cache.Policy -> Gate
An empty gateway: capacity requests at once, and an empty cache.
def give.released source · line 35 · raw
@r:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Release -> @rest:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @cache:0x874f22564c9f7947263463f6904f7d44/cache.Cache<String> -> Finish
def give.split source · line 42 · raw
@s:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Split -> @pool:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @cache:0x874f22564c9f7947263463f6904f7d44/cache.Cache<String> -> Finish
def give source · line 50 · raw
@pool:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @held:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @cache:0x874f22564c9f7947263463f6904f7d44/cache.Cache<String> -> Finish
Gives one lent unit back to the pool. Unheld means that no unit was lent.
def start.ticket source · line 54 · raw
@r:Pair(0x874f22564c9f7947263463f6904f7d44/cache.Ticket, 0x874f22564c9f7947263463f6904f7d44/cache.Cache<String>) -> Pair(Pending, 0x874f22564c9f7947263463f6904f7d44/cache.Cache<String>)
Starts a fetch of key at clock at, as data.
def start source · line 59 · raw
@cache:0x874f22564c9f7947263463f6904f7d44/cache.Cache<String> -> @+key:String -> @at:Nat -> Pair(Pending, 0x874f22564c9f7947263463f6904f7d44/cache.Cache<String>)
def settle source · line 63 · raw
@cache:0x874f22564c9f7947263463f6904f7d44/cache.Cache<String> -> @p:Pending -> @u:Upstream -> 0x874f22564c9f7947263463f6904f7d44/cache.Cache<String>
Stores what a fetch found. A failed fetch stores nothing.
def begin.fetch source · line 71 · raw
@pool:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @held:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @r:Pair(Pending, 0x874f22564c9f7947263463f6904f7d44/cache.Cache<String>) -> Begin
def begin.refund source · line 76 · raw
@r:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Release -> @held:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @cache:0x874f22564c9f7947263463f6904f7d44/cache.Cache<String> -> Begin
The joined grant names another pool: give the new unit back and refuse.
def begin.fresh source · line 83 · raw
@f:Finish -> @e:0x874f22564c9f7947263463f6904f7d44/cache.Entry<String> -> Begin
def begin.read source · line 90 · raw
@m:Maybe<&2, 0x874f22564c9f7947263463f6904f7d44/cache.Entry<String>> -> @pool:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @held:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @cache:0x874f22564c9f7947263463f6904f7d44/cache.Cache<String> -> @+key:String -> @+now:Nat -> Begin
def begin.joined source · line 97 · raw
@j:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Combine -> @pool:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @+cache:0x874f22564c9f7947263463f6904f7d44/cache.Cache<String> -> @+key:String -> @+now:Nat -> Begin
def begin.took source · line 104 · raw
@r:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Reserve -> @held:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @cache:0x874f22564c9f7947263463f6904f7d44/cache.Cache<String> -> @+key:String -> @+now:Nat -> Begin
def begin.granted source · line 111 · raw
@ok:Bool -> @gate:Gate -> @+key:String -> @+now:Nat -> Begin
def begin source · line 121 · raw
@policy:0xdb1e37671e3c0872f3bf78d730b5b176/authz.Policy -> @req:0xdb1e37671e3c0872f3bf78d730b5b176/authz.Request -> @gate:Gate -> @+key:String -> @+now:Nat -> Begin
Authorizes req, takes one unit, and reads key at now. Fresh has given its
unit back; Fetch keeps it until finish.
def finish source · line 125 · raw
@gate:Gate -> @p:Pending -> @u:Upstream -> Finish
Stores what the fetch did and gives its unit back.