Leader.Leader.run: def of bend-kube-runtime@0.2.0.0 Import: import bend-kube-runtime@0.2.0.0/src/leader.bend as Leader Lines 96-136 of bend-kube-runtime@0.2.0.0/src/leader.bend: https://jend.leeeet.dev/read.txt?path=bend-kube-runtime@0.2.0.0/src/leader.bend&start_line=96&end_line=136 import Base import bend-kube-runtime@0.2.0.0/src/json.bend as J import bend-kube-runtime@0.2.0.0/src/config.bend as K import bend-kube-runtime@0.2.0.0/src/client.bend as Cl import bend-kube-runtime@0.2.0.0/src/time.bend as T import bend-kube-runtime@0.2.0.0/src/sys.bend as Y import bend-kube-runtime@0.2.0.0/src/log.bend as L import bend-kube-runtime@0.2.0.0/src/lease.bend as E # The election loop. start runs once, when the lease is first ours. def Leader.run(fuel: Nat, ev: LEv, +cfg: K.Config, +o: LOpts, +obs: E.Obs, +leading: Bool, +last: U32, start: Maybe<&1, IO(Unit)>) -> IO(Unit): match fuel ev: case 0n e: IO.pure(Unit, Unit{}) case 1n+f LTry{}: IO.bind(U32 & (U32 & U32), Unit, Y.Sys.wall(), w => IO.bind(Result<&2, &2, Cl.KErr, J.Json>, Unit, Cl.Client.get(cfg, LOpts.api(o), LOpts.name(o)), r => Leader.run(f, LRead{T.Wall.of(w), r}, cfg, o, obs, leading, last, start))) case 1n+f LRead{+w, r}: Leader.run(f, LDecided{T.Wall.ms(w), Leader.decide(Leader.read(r), o, obs, w)}, cfg, o, obs, leading, last, start) case 1n+f LDecided{+now, Done{E.Decision{E.LCreate{l}, ob}}}: IO.bind(Result<&2, &2, Cl.KErr, J.Json>, Unit, Cl.Client.create(cfg, LOpts.api(o), l), r => Leader.run(f, LWrote{now, Leader.wrote(r), Leader.late(now, last, LOpts.deadline(o))}, cfg, o, ob, leading, last, start)) case 1n+f LDecided{+now, Done{E.Decision{E.LUpdate{l}, ob}}}: IO.bind(Result<&2, &2, Cl.KErr, J.Json>, Unit, Cl.Client.replace(cfg, LOpts.api(o), LOpts.name(o), l), r => Leader.run(f, LWrote{now, Leader.wrote(r), Leader.late(now, last, LOpts.deadline(o))}, cfg, o, ob, leading, last, start)) case 1n+f LDecided{+now, Done{E.Decision{E.LWait{}, ob}}}: Leader.run(f, LWrote{now, False{}, Leader.late(now, last, LOpts.deadline(o))}, cfg, o, ob, leading, last, start) case 1n+f LDecided{+now, Fail{e}}: IO.bind(Unit, Unit, L.Log.warn("lease read failed", [L.Log.kv("error", Cl.KErr.show(e))]), u => Leader.run(f, LWrote{now, False{}, Leader.late(now, last, LOpts.deadline(o))}, cfg, o, obs, leading, last, start)) case 1n+f LWrote{now, True{}, late}: IO.bind(Unit, Unit, Leader.started(leading, start), u => IO.bind(Unit, Unit, IO.sleep(LOpts.retry(o)), u2 => Leader.run(f, LTry{}, cfg, o, obs, True{}, now, None{}))) case 1n+f LWrote{now, False{}, late}: Leader.run(f, LFail{Bool.and(leading, late)}, cfg, o, obs, leading, last, start) case 1n+f LFail{True{}}: Leader.lost() case 1n+f LFail{False{}}: IO.bind(Unit, Unit, IO.sleep(LOpts.retry(o)), u => Leader.run(f, LTry{}, cfg, o, obs, leading, last, start)) Uses (40): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.and https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO.bind https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO.pure https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO.sleep https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Maybe https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Pair https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Result https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Unit https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/client.bend&name=Client.create https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/client.bend&name=Client.get https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/client.bend&name=Client.replace https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/client.bend&name=KErr https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/client.bend&name=KErr.show https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/config.bend&name=Config https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/json.bend&name=Json https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/leader.bend&name=LEv https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/leader.bend&name=LOpts https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/leader.bend&name=LOpts.api https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/leader.bend&name=LOpts.deadline https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/leader.bend&name=LOpts.name https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/leader.bend&name=LOpts.retry https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/leader.bend&name=Leader.decide https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/leader.bend&name=Leader.late https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/leader.bend&name=Leader.lost https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/leader.bend&name=Leader.read https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/leader.bend&name=Leader.started https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/leader.bend&name=Leader.wrote https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/lease.bend&name=Decision https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/lease.bend&name=LeaseAct https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/lease.bend&name=Obs https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/log.bend&name=Log.kv https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/log.bend&name=Log.warn https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/sys.bend&name=Sys.wall https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/time.bend&name=Wall.ms https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/time.bend&name=Wall.of