Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-resilience

Resilience pipelines for Pudu: retry, circuit breaker, timeout, fallback, hedging, rate limiting, and chaos injection

0.1.0Apache-2.01

InstallClose

Strategy.pudu

Pudu42 lines1.7 KB

GitHub ↗
1/** @Resilience.Strategy.Contract — one layer of a resilience pipeline */2module PuduLangResilience.Strategy34import PuduLangResilience.Clock as Clock5import PuduLangResilience.Context as Context6import PuduLangResilience.Randomizer as Randomizer7import PuduLangResilience as Resilience8import PuduLangResilience.Telemetry as Telemetry910/** @Resilience.Strategy.Callback — the work a layer guards */11export type Callback[T, E] = fn(Context.Context) -> Resilience.Outcome[T, E]1213/** @Resilience.Strategy.Runtime — the effects a pipeline lends its layers */14export type Runtime = { clock: Clock.Clock, randomizer: Randomizer.Randomizer, telemetry: Telemetry.Reporter }1516/** @Resilience.Strategy.Execute — runs a callback under one layer's policy */17export type Execute[T, E] = fn(Runtime, Context.Context, Callback[T, E]) -> Resilience.Outcome[T, E]1819/** @Resilience.Strategy.Strategy — a named, validated policy layer */20export type Strategy[T, E] = {21  name: Option[Str],22  kind: Str,23  summary: Str,24  problems: Array[Str],25  attach: fn(Runtime) -> (),26  execute: Execute[T, E]27}2829/// A strategy of the given kind that runs `execute` around every callback. `name` identifies it30/// in telemetry and must be unique within one pipeline.31export fn custom[T, E](name: Option[Str], kind: Str, execute: Execute[T, E]) -> Strategy[T, E] {32  Strategy{name: name, kind: kind, summary: kind, problems: [], attach: detached, execute: execute}33}3435/// Keeps nothing of the runtime; the `attach` of a strategy that holds no state between calls.36export fn detached(_runtime: Runtime) -> () { () }3738/// A runtime on the system clock and randomizer that reports nothing.39export fn standalone() -> Runtime {40  Runtime{clock: Clock.system(), randomizer: Randomizer.system(), telemetry: Telemetry.silent()}41}42