Liking cljdoc? Tell your friends :D

fx.schedule

Composable, pure schedules, recurrence policies, retries, and resilience primitives for fx.

Composable, pure schedules, recurrence policies, retries, and resilience primitives for fx.
raw docstring

and-then>clj/s

(and-then> sched-a sched-b)

Sequentially composes two schedules. Runs sched-a to exhaustion, then seamlessly continues with sched-b.

Sequentially composes two schedules. Runs `sched-a` to exhaustion, then seamlessly continues with `sched-b`.
raw docstring

circuit-breaker-stateclj/s

(circuit-breaker-state breaker-atom)

Returns current state keyword (:closed, :open, or :half-open) of a circuit breaker atom.

Returns current state keyword (`:closed`, `:open`, or `:half-open`) of a circuit breaker atom.
raw docstring

circuit-breaker>clj/s

(circuit-breaker> breaker-or-opts)
(circuit-breaker> target-or-breaker breaker-or-opts)
(circuit-breaker> prev-effect target-effect breaker-or-opts)

Wraps an effect with stateful circuit breaker protection. When open, fast-fails immediately with :circuit-breaker/open without executing the inner effect.

Accepts either a circuit breaker atom (from make-circuit-breaker) or an options map.

Supports standalone execution and pipeline usage: (circuit-breaker> (fetch-remote>) breaker) (-> (fetch-remote>) (circuit-breaker> {:failure-threshold 5 :reset-timeout-ms 10000}))

Wraps an effect with stateful circuit breaker protection.
When open, fast-fails immediately with `:circuit-breaker/open` without executing the inner effect.

Accepts either a circuit breaker atom (from `make-circuit-breaker`) or an options map.

Supports standalone execution and pipeline usage:
  (circuit-breaker> (fetch-remote>) breaker)
  (-> (fetch-remote>) (circuit-breaker> {:failure-threshold 5 :reset-timeout-ms 10000}))
raw docstring

elapsed>clj/s

(elapsed> max-duration-ms)

Creates a schedule that recurs as long as the elapsed time since start is less than max-duration-ms. Outputs elapsed time in milliseconds.

Creates a schedule that recurs as long as the elapsed time since start is less than `max-duration-ms`.
Outputs elapsed time in milliseconds.
raw docstring

exponential-backoff>clj/s

(exponential-backoff>)
(exponential-backoff> opts)

Creates a schedule that increases delay exponentially ((* initial-ms (Math/pow factor attempt))). Options map: :initial-ms - base delay in milliseconds (default: 100) :factor - exponential growth multiplier (default: 2.0) :max-ms - optional ceiling cap in milliseconds

Creates a schedule that increases delay exponentially (`(* initial-ms (Math/pow factor attempt))`).
Options map:
  `:initial-ms` - base delay in milliseconds (default: 100)
  `:factor`     - exponential growth multiplier (default: 2.0)
  `:max-ms`     - optional ceiling cap in milliseconds
raw docstring

fibonacci-backoff>clj/s

(fibonacci-backoff>)
(fibonacci-backoff> opts)

Creates a schedule that increases delay according to the Fibonacci sequence. Options map: :initial-ms - base delay multiplier in milliseconds (default: 100) :max-ms - optional ceiling cap in milliseconds

Creates a schedule that increases delay according to the Fibonacci sequence.
Options map:
  `:initial-ms` - base delay multiplier in milliseconds (default: 100)
  `:max-ms`     - optional ceiling cap in milliseconds
raw docstring

fixed>clj/s

(fixed> delay-ms)

Creates a schedule that recurs indefinitely with a constant delay-ms interval. Outputs the total count of completed recurrences.

Creates a schedule that recurs indefinitely with a constant `delay-ms` interval.
Outputs the total count of completed recurrences.
raw docstring

forever>clj/s

(forever>)

Creates a schedule that recurs indefinitely with 0 delay. Outputs the total count of completed recurrences.

Creates a schedule that recurs indefinitely with 0 delay.
Outputs the total count of completed recurrences.
raw docstring

intersect>clj/s

(intersect> sched-a sched-b)

Combines two schedules into one that recurs only as long as both schedules recur. Uses the maximum delay of both schedules on each step. Outputs a pair [out-a out-b].

Combines two schedules into one that recurs only as long as *both* schedules recur.
Uses the maximum delay of both schedules on each step.
Outputs a pair `[out-a out-b]`.
raw docstring

IScheduleclj/sprotocol

Protocol for composable schedule state machines.

Protocol for composable schedule state machines.

-initial-stateclj/s

(-initial-state this)

Returns the initial state value for the schedule.

Returns the initial state value for the schedule.

-stepclj/s

(-step this state now input)

Performs a single transition step given current state, timestamp now (ms), and input. Returns a map: {:decision :recur | :halt :delay-ms <long> :state <any> :out <any>}

Performs a single transition step given current `state`, timestamp `now` (ms), and `input`.
Returns a map:
  {:decision :recur | :halt
   :delay-ms <long>
   :state    <any>
   :out      <any>}
raw docstring

jitter>clj/s

(jitter> schedule)
(jitter> schedule factor)

Applies randomized jitter [(* delay (- 1.0 factor)), (* delay (+ 1.0 factor))] to schedule delays. factor defaults to 0.1 (10% variance).

Applies randomized jitter `[(* delay (- 1.0 factor)), (* delay (+ 1.0 factor))]` to schedule delays.
`factor` defaults to 0.1 (10% variance).
raw docstring

linear-backoff>clj/s

(linear-backoff>)
(linear-backoff> opts)

Creates a schedule that increases delay linearly ((* initial-ms attempt)). Options map: :initial-ms - base delay in milliseconds (default: 100) :max-ms - optional ceiling cap in milliseconds

Creates a schedule that increases delay linearly (`(* initial-ms attempt)`).
Options map:
  `:initial-ms` - base delay in milliseconds (default: 100)
  `:max-ms`     - optional ceiling cap in milliseconds
raw docstring

make-circuit-breakerclj/s

(make-circuit-breaker)
(make-circuit-breaker opts)

Creates a new stateful circuit breaker atom with initial state :closed. Options map: :failure-threshold - consecutive failure count before opening (default: 3) :reset-timeout-ms - milliseconds before attempting half-open probe (default: 5000) :trip-on? - predicate on IFailure deciding if it counts toward tripping (default: (constantly true)) :on-state-change - optional callback (fn [old-state new-state])

Creates a new stateful circuit breaker atom with initial state `:closed`.
Options map:
  `:failure-threshold` - consecutive failure count before opening (default: 3)
  `:reset-timeout-ms`  - milliseconds before attempting half-open probe (default: 5000)
  `:trip-on?`          - predicate on `IFailure` deciding if it counts toward tripping (default: (constantly true))
  `:on-state-change`   - optional callback `(fn [old-state new-state])`
raw docstring

make-rate-limiterclj/s

(make-rate-limiter)
(make-rate-limiter opts)

Creates a new stateful token-bucket rate limiter atom. Options map: :limit - maximum token capacity / burst limit (default: 10) :interval-ms - time window in milliseconds for full replenishment (default: 1000)

Creates a new stateful token-bucket rate limiter atom.
Options map:
  `:limit`        - maximum token capacity / burst limit (default: 10)
  `:interval-ms`  - time window in milliseconds for full replenishment (default: 1000)
raw docstring

make-scheduleclj/s

(make-schedule initial-state-fn step-fn)

Constructs an ISchedule instance given an initial-state-fn and step-fn.

Constructs an ISchedule instance given an `initial-state-fn` and `step-fn`.
raw docstring

map-output>clj/s

(map-output> schedule f)

Purely transforms the :out value produced by each step of the schedule with (f out).

Purely transforms the `:out` value produced by each step of the schedule with `(f out)`.
raw docstring

modify-delay>clj/s

(modify-delay> schedule f)

Transforms the computed delay of a schedule using pure function (f delay-ms state) or (f delay-ms).

Transforms the computed delay of a schedule using pure function `(f delay-ms state)` or `(f delay-ms)`.
raw docstring

once>clj/s

(once>)

Creates a schedule that recurs exactly once with 0 delay.

Creates a schedule that recurs exactly once with 0 delay.
raw docstring

rate-limiter>clj/s

(rate-limiter> limiter-or-opts)
(rate-limiter> target-or-limiter limiter-or-opts)
(rate-limiter> prev-effect target-effect limiter-or-opts)

Wraps an effect with token-bucket rate limiting. When token budget is exhausted, fails fast with :rate-limiter/exceeded.

Accepts either a rate limiter atom (from make-rate-limiter) or an options map.

Supports standalone execution and pipeline usage: (rate-limiter> (call-api>) limiter) (-> (call-api>) (rate-limiter> {:limit 5 :interval-ms 1000}))

Wraps an effect with token-bucket rate limiting.
When token budget is exhausted, fails fast with `:rate-limiter/exceeded`.

Accepts either a rate limiter atom (from `make-rate-limiter`) or an options map.

Supports standalone execution and pipeline usage:
  (rate-limiter> (call-api>) limiter)
  (-> (call-api>) (rate-limiter> {:limit 5 :interval-ms 1000}))
raw docstring

recur-n>clj/s

(recur-n> n)

Creates a schedule that recurs at most n times with 0 delay. Outputs the total count of completed recurrences.

Creates a schedule that recurs at most `n` times with 0 delay.
Outputs the total count of completed recurrences.
raw docstring

repeat-schedule>clj/s

(repeat-schedule> schedule)
(repeat-schedule> target-or-schedule schedule-or-nil)
(repeat-schedule> prev-effect target-effect schedule)

Repeats effect on success according to schedule. Halts and propagates failure immediately if effect fails, or returns the last success value when schedule halts.

Supports standalone execution and pipeline usage: (repeat-schedule> (poll-job>) (fixed> 1000)) (-> (poll-job>) (repeat-schedule> (recur-n> 5)))

Repeats `effect` on success according to `schedule`.
Halts and propagates failure immediately if `effect` fails, or returns the last success value when schedule halts.

Supports standalone execution and pipeline usage:
  (repeat-schedule> (poll-job>) (fixed> 1000))
  (-> (poll-job>) (repeat-schedule> (recur-n> 5)))
raw docstring

retry-schedule>clj/s

(retry-schedule> schedule)
(retry-schedule> target-or-schedule schedule-or-nil)
(retry-schedule> prev-effect target-effect schedule)

Retries effect on failure according to schedule. Halts and returns the successful value when effect succeeds, or the final failure if the schedule halts.

Supports standalone execution and pipeline usage: (retry-schedule> (fetch-data>) (exponential-backoff>)) (-> (fetch-data>) (retry-schedule> (recur-n> 3)))

Retries `effect` on failure according to `schedule`.
Halts and returns the successful value when `effect` succeeds, or the final failure if the schedule halts.

Supports standalone execution and pipeline usage:
  (retry-schedule> (fetch-data>) (exponential-backoff>))
  (-> (fetch-data>) (retry-schedule> (recur-n> 3)))
raw docstring

schedule>clj/s

(schedule> schedule)
(schedule> target-or-schedule schedule-or-nil)
(schedule> prev-effect target-effect schedule)

Evaluates effect continually according to schedule on both success and failure until schedule halts.

Supports standalone execution and pipeline usage: (schedule> (poll-job>) (fixed> 500)) (-> (poll-job>) (schedule> (recur-n> 3)))

Evaluates `effect` continually according to `schedule` on both success and failure until schedule halts.

Supports standalone execution and pipeline usage:
  (schedule> (poll-job>) (fixed> 500))
  (-> (poll-job>) (schedule> (recur-n> 3)))
raw docstring

schedule?clj/s

(schedule? x)

Returns true if x satisfies ISchedule.

Returns true if `x` satisfies ISchedule.
raw docstring

step-schedule!clj/s

(step-schedule! schedule state input)
(step-schedule! schedule state now input)

Drives a single step evaluation of schedule given current state, optional now timestamp (ms), and input. Returns {:decision :recur | :halt, :delay-ms <long>, :state <any>, :out <any>}.

Drives a single step evaluation of `schedule` given current `state`, optional `now` timestamp (ms), and `input`.
Returns `{:decision :recur | :halt, :delay-ms <long>, :state <any>, :out <any>}`.
raw docstring

tap-step>clj/s

(tap-step> schedule tap-fn)

Executes a non-interfering side effect (tap-fn {:decision d :delay-ms ms :input in :out out :state st}) after each schedule step.

Executes a non-interfering side effect `(tap-fn {:decision d :delay-ms ms :input in :out out :state st})`
after each schedule step.
raw docstring

union>clj/s

(union> sched-a sched-b)

Combines two schedules into one that recurs as long as either schedule recurs. Uses the minimum delay of both continuing schedules on each step. Outputs a pair [out-a out-b].

Combines two schedules into one that recurs as long as *either* schedule recurs.
Uses the minimum delay of both continuing schedules on each step.
Outputs a pair `[out-a out-b]`.
raw docstring

until-input>clj/s

(until-input> schedule pred)

Recurs until (pred input) returns truthy (halts when (pred input) is truthy).

Recurs until `(pred input)` returns truthy (halts when `(pred input)` is truthy).
raw docstring

until-output>clj/s

(until-output> schedule pred)

Recurs until (pred output) of the step result returns truthy.

Recurs until `(pred output)` of the step result returns truthy.
raw docstring

until-tag>clj/s

(until-tag> schedule halt-tag)

Filters a retry schedule to halt when failure :tag matches halt-tag (keyword or set of keywords).

Filters a retry schedule to halt when failure `:tag` matches `halt-tag` (keyword or set of keywords).
raw docstring

while-input>clj/s

(while-input> schedule pred)

Recurs only while (pred input) returns truthy.

Recurs only while `(pred input)` returns truthy.
raw docstring

while-output>clj/s

(while-output> schedule pred)

Recurs only while (pred output) of the step result returns truthy.

Recurs only while `(pred output)` of the step result returns truthy.
raw docstring

while-tag>clj/s

(while-tag> schedule expected-tag)

Filters a retry schedule to recur only when failure :tag matches expected-tag (keyword or set of keywords).

Filters a retry schedule to recur only when failure `:tag` matches `expected-tag` (keyword or set of keywords).
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close