ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Worker

Description

Mirror worker entry points and supervision. Queued jobs receive current policy and first-party checks before any public fetch. The queue can outlive the deployment's first-party declarations.

Synopsis

Worker runtime

data WorkerRuntime Source #

The effectful backends the mirror worker closes over, read through the WorkerM reader.

Constructors

WorkerRuntime 

Fields

Instances

Instances details
MonadReader WorkerRuntime WorkerM Source # 
Instance details

Defined in Ecluse.Core.Worker.Types

Per-ecosystem ingest re-evaluation

data WorkerPolicy Source #

Use the served mount's resolver, rules, and gates for worker admission.

Constructors

WorkerPolicy 

Fields

type WorkerPolicies = Map Ecosystem WorkerPolicy Source #

Key bundles by ecosystem. Jobs without a bundle are dropped without publication.

The worker monad

data WorkerM a Source #

Carry worker runtime and logging context through ReaderT, without mutable request state.

Instances

Instances details
MonadIO WorkerM Source # 
Instance details

Defined in Ecluse.Core.Worker.Types

Methods

liftIO :: IO a -> WorkerM a #

Applicative WorkerM Source # 
Instance details

Defined in Ecluse.Core.Worker.Types

Methods

pure :: a -> WorkerM a #

(<*>) :: WorkerM (a -> b) -> WorkerM a -> WorkerM b #

liftA2 :: (a -> b -> c) -> WorkerM a -> WorkerM b -> WorkerM c #

(*>) :: WorkerM a -> WorkerM b -> WorkerM b #

(<*) :: WorkerM a -> WorkerM b -> WorkerM a #

Functor WorkerM Source # 
Instance details

Defined in Ecluse.Core.Worker.Types

Methods

fmap :: (a -> b) -> WorkerM a -> WorkerM b #

(<$) :: a -> WorkerM b -> WorkerM a #

Monad WorkerM Source # 
Instance details

Defined in Ecluse.Core.Worker.Types

Methods

(>>=) :: WorkerM a -> (a -> WorkerM b) -> WorkerM b #

(>>) :: WorkerM a -> WorkerM b -> WorkerM b #

return :: a -> WorkerM a #

Katip WorkerM Source # 
Instance details

Defined in Ecluse.Core.Worker.Types

KatipContext WorkerM Source # 
Instance details

Defined in Ecluse.Core.Worker.Types

MonadUnliftIO WorkerM Source # 
Instance details

Defined in Ecluse.Core.Worker.Types

Methods

withRunInIO :: ((forall a. WorkerM a -> IO a) -> IO b) -> WorkerM b #

MonadReader WorkerRuntime WorkerM Source # 
Instance details

Defined in Ecluse.Core.Worker.Types

runWorkerM :: LogEnv -> SimpleLogPayload -> WorkerRuntime -> WorkerM a -> IO a Source #

Run under the caller's logging environment and trace context.

Loop and job processing (exposed for direct testing)

workerLoop :: SupervisionPolicy -> WorkerM Void Source #

The continuous consume loop: long-poll, process, repeat, under the supervision policy. The heartbeat advances only on progress, so a persistently faulting receive goes stale on /livez.

processBatch :: [QueueMessage] -> WorkerM () Source #

Process one batch sequentially under a lease on every receipt in it. The heartbeat advances per job, so workerHeartbeatStaleAfter covers one job.

processJob :: MirrorJob -> WorkerM JobOutcome Source #

Recheck current policy before publishing because queue delays are unbounded.

data JobOutcome Source #

A mirror outcome determines acknowledgement, redelivery, or dead-letter handling.

Constructors

Succeeded

Completion proof covers every expected file and companion, including idempotent redelivery.

Dropped Text

A non-retryable rejection. The worker alarms and acknowledges the message.

SourceUnavailable Text

The source version object is unavailable. Retire the job separately from a policy denial.

DeadLettered Text

A terminal fault sent to the dead-letter handler instead of silently deleted.

Retried RetryLeg Text

A transient fault leaves the message unacknowledged and retains the failed leg.

Instances

Instances details
Show JobOutcome Source # 
Instance details

Defined in Ecluse.Core.Worker.Job

Eq JobOutcome Source # 
Instance details

Defined in Ecluse.Core.Worker.Job

data RetryLeg Source #

The failed leg determines whether the worker resets queue visibility.

Constructors

BeforePublish

A failure before publication keeps the lease until redelivery.

AfterPublish

A transient publication failure releases the message for immediate redelivery.

Instances

Instances details
Show RetryLeg Source # 
Instance details

Defined in Ecluse.Core.Worker.Job

Eq RetryLeg Source # 
Instance details

Defined in Ecluse.Core.Worker.Job

Liveness

data WorkerHeartbeat Source #

Worker progress and its startup allowance, separate from HTTP readiness.

newWorkerHeartbeat :: IO WorkerHeartbeat Source #

Build a fresh WorkerHeartbeat with no poll yet recorded (lastPoll is Nothing until the worker's first successful receive).

recordPoll :: WorkerHeartbeat -> UTCTime -> IO () Source #

Stamp the heartbeat with the given instant, recording a unit of worker progress. The worker calls it through recordWorkerProgress.

lastPoll :: WorkerHeartbeat -> IO (Maybe UTCTime) Source #

The instant of the worker's last recorded progress, a successful poll or a completed job, or Nothing before its first.

workerJobStepAllowance :: NominalDiffTime Source #

How long one long job step may run: uploading the largest artifact the memory plan admits (512 MiB) over a 2 MiB-per-second link. Renewing a receipt's visibility never extends it.

workerHeartbeatStaleAfter :: NominalDiffTime Source #

Startup and progress allowance: a fetch and a publish of that largest artifact plus a minute, so a slow job never restarts the process.

heartbeatHealthy :: UTCTime -> UTCTime -> Maybe UTCTime -> Bool Source #

Judge progress at now, using startup time only until the first successful progress.

data Liveness Source #

What /livez answers from: the health verdict, plus the instant the checked loop last recorded progress so an orchestrator can judge staleness rather than only pass or fail.

Constructors

Liveness 

Fields

Instances

Instances details
Show Liveness Source # 
Instance details

Defined in Ecluse.Core.Worker.Liveness

Eq Liveness Source # 
Instance details

Defined in Ecluse.Core.Worker.Liveness

alwaysLive :: Liveness Source #

The verdict of a role with no background loop to stall: live, with nothing to report.

heartbeatLivenessNow :: WorkerHeartbeat -> IO Liveness Source #

Read the worker heartbeat and judge it against the current wall clock, keeping the instant judged. Both the embedded and the dedicated worker answer /livez through this.