ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Breaker

Description

A clock-injected circuit breaker for advisory reads and credential mints. Recovery admits one owner for a complete run. Tickets fence older outcomes and cleanup. Callers commit transitions atomically and release tickets on every exit.

Synopsis

State and phase

data Breaker Source #

Opaque state retaining its generation through settlement and cancellation.

Instances

Instances details
Show Breaker Source # 
Instance details

Defined in Ecluse.Core.Breaker

Eq Breaker Source # 
Instance details

Defined in Ecluse.Core.Breaker

Methods

(==) :: Breaker -> Breaker -> Bool #

(/=) :: Breaker -> Breaker -> Bool #

data BreakerPhase Source #

The phase view excludes the generation used to fence stale owners.

Constructors

Closed Int

Healthy, with its consecutive failure count.

Open UTCTime

Refuses calls before this cooldown deadline.

HalfOpen

One admitted run owns recovery.

RecoveryReady

Cancelled recovery permits another probe immediately.

Instances

Instances details
Show BreakerPhase Source # 
Instance details

Defined in Ecluse.Core.Breaker

Eq BreakerPhase Source # 
Instance details

Defined in Ecluse.Core.Breaker

initialBreaker :: Breaker Source #

A healthy breaker with no failures.

breakerPhase :: Breaker -> BreakerPhase Source #

Observe the phase without exposing an ownership ticket.

Owned attempts

data Attempt Source #

A ticket for an admitted run. Only its recovery generation can settle an owned probe.

Instances

Instances details
Show Attempt Source # 
Instance details

Defined in Ecluse.Core.Breaker

Eq Attempt Source # 
Instance details

Defined in Ecluse.Core.Breaker

Methods

(==) :: Attempt -> Attempt -> Bool #

(/=) :: Attempt -> Attempt -> Bool #

admit :: UTCTime -> Breaker -> (Maybe Attempt, Breaker) Source #

Commit the returned state atomically and release the admitted ticket on every exit.

recordSuccess :: Attempt -> Breaker -> Breaker Source #

Matching success closes the breaker. An older outcome leaves it unchanged.

recordFailure :: Int -> NominalDiffTime -> UTCTime -> Attempt -> Breaker -> Breaker Source #

Count an admitted failure once per exhausted run, with a fresh cooldown after a failed probe.

release :: Attempt -> Breaker -> Breaker Source #

Release unsettled recovery without adding a failure or cooldown. Stale releases do nothing.

Observations

newtype BreakerReporter Source #

Observe changes through the composition root's instrument adapter.

Constructors

BreakerReporter (Breaker -> IO ()) 

noBreakerReporter :: BreakerReporter Source #

Discard transitions.

reportBreakerChange :: BreakerReporter -> Breaker -> Breaker -> IO () Source #

Report coarse phase changes. Failure counts and ownership generations do not emit events.

breakerState :: Breaker -> BreakerState Source #

Project the phase onto the existing three gauge values.