Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains all the types used across all the other modules
Synopsis
- type CapatazId = UUID
- type WorkerId = UUID
- type SupervisorId = UUID
- type ProcessId = UUID
- type WorkerAction m = WorkerId -> m ()
- type ProcessName = Text
- type CapatazName = Text
- type SupervisorName = Text
- type WorkerName = Text
- type RestartCount = Int
- type ProcessMap m = HashMap ProcessId (Process m)
- type ParentSupervisor = Supervisor
- newtype ProcessThreadId = PTID ThreadId
- data CapatazEvent
- = InvalidSupervisorStatusReached { }
- | SupervisorStatusChanged { }
- | ProcessTerminated { }
- | ProcessStarted { }
- | ProcessRestarted { }
- | ProcessCompleted { }
- | ProcessFailed { }
- | ProcessCallbackExecuted { }
- | ProcessTerminationStarted { }
- | ProcessTerminationFinished { }
- | CapatazFailed { }
- | CapatazTerminated { }
- data WorkerTerminationPolicy
- defWorkerTerminationPolicy :: WorkerTerminationPolicy
- data ProcessRestartAction
- data ProcessTerminationOrder
- defProcessTerminationOrder :: ProcessTerminationOrder
- data SupervisorRestartStrategy
- defSupervisorRestartStategy :: SupervisorRestartStrategy
- data CapatazOptions m = CapatazOptions {
- supervisorName :: !SupervisorName
- supervisorIntensity :: !Int
- supervisorPeriodSeconds :: !NominalDiffTime
- supervisorRestartStrategy :: !SupervisorRestartStrategy
- supervisorProcessSpecList :: ![ProcessSpec m]
- supervisorProcessTerminationOrder :: !ProcessTerminationOrder
- supervisorOnIntensityReached :: !(m ())
- supervisorOnFailure :: !(SomeException -> m ())
- notifyEvent :: !(CapatazEvent -> m ())
- data WorkerRestartStrategy
- defWorkerRestartStrategy :: WorkerRestartStrategy
- data WorkerOptions m = WorkerOptions {
- workerAction :: WorkerAction m
- workerName :: !WorkerName
- workerOnFailure :: !(SomeException -> m ())
- workerOnCompletion :: !(m ())
- workerOnTermination :: !(m ())
- workerTerminationPolicy :: !WorkerTerminationPolicy
- workerRestartStrategy :: !WorkerRestartStrategy
- data Worker m = Worker {
- workerId :: !WorkerId
- workerAsync :: !(Async ())
- workerCreationTime :: !UTCTime
- workerName :: !WorkerName
- workerOptions :: !(WorkerOptions m)
- data ProcessEnv = ProcessEnv {}
- data SupervisorOptions m = SupervisorOptions {
- supervisorName :: Text
- supervisorIntensity :: !Int
- supervisorPeriodSeconds :: !NominalDiffTime
- supervisorRestartStrategy :: !SupervisorRestartStrategy
- supervisorProcessSpecList :: ![ProcessSpec m]
- supervisorProcessTerminationOrder :: !ProcessTerminationOrder
- supervisorOnIntensityReached :: !(m ())
- supervisorOnFailure :: !(SomeException -> m ())
- data Supervisor m = Supervisor {
- supervisorId :: !SupervisorId
- supervisorName :: !SupervisorName
- supervisorOptions :: !(SupervisorOptions m)
- supervisorCreationTime :: !UTCTime
- supervisorAsync :: !(Async ())
- supervisorNotify :: SupervisorMessage m -> m ()
- supervisorEnv :: !(SupervisorEnv m)
- data ControlAction m
- = ForkWorker {
- workerOptions :: !(WorkerOptions m)
- returnWorkerId :: !(WorkerId -> m ())
- | ForkSupervisor {
- supervisorOptions :: !(SupervisorOptions m)
- returnSupervisor :: !(Supervisor m -> m ())
- | TerminateProcess {
- processId :: !ProcessId
- processTerminationReason :: !Text
- notifyProcessTermination :: !(Bool -> m ())
- = ForkWorker {
- data CapatazSignal
- data CapatazError = SupervisorIntensityReached {}
- data CallbackType
- data ProcessType
- data ProcessError = ProcessCallbackFailed {}
- data MonitorEvent
- = ProcessTerminated' { }
- | ProcessFailed' { }
- | ProcessCompleted' { }
- | ProcessForcedRestart { }
- data SupervisorStatus
- = Initializing
- | Running
- | Halting
- | Halted
- data SupervisorMessage m
- data Process m
- = WorkerProcess !(Worker m)
- | SupervisorProcess !(Supervisor m)
- data ProcessSpec m
- = WorkerSpec (WorkerOptions m)
- | SupervisorSpec (SupervisorOptions m)
- data Capataz m = Capataz {
- capatazSupervisor :: !(Supervisor m)
- capatazTeardown :: !Teardown
- data ParentSupervisorEnv m = ParentSupervisorEnv {
- supervisorId :: !SupervisorId
- supervisorName :: !SupervisorName
- supervisorNotify :: !(SupervisorMessage m -> m ())
- notifyEvent :: !(CapatazEvent -> m ())
- data SupervisorEnv m = SupervisorEnv {
- supervisorId :: !SupervisorId
- supervisorName :: !SupervisorName
- supervisorNotify :: !(SupervisorMessage m -> m ())
- supervisorGetNotification :: !(STM (SupervisorMessage m))
- supervisorProcessMap :: !(IORef (ProcessMap m))
- supervisorStatusVar :: !(TVar SupervisorStatus)
- supervisorOptions :: !(SupervisorOptions m)
- supervisorIntensity :: !Int
- supervisorPeriodSeconds :: !NominalDiffTime
- supervisorRestartStrategy :: !SupervisorRestartStrategy
- supervisorProcessTerminationOrder :: !ProcessTerminationOrder
- supervisorOnIntensityReached :: !(m ())
- supervisorOnIntensityReached :: !(SomeException -> m ())
- notifyEvent :: !(CapatazEvent -> m ())
- defCapatazOptions :: Monad m => Text -> (CapatazOptions m -> CapatazOptions m) -> CapatazOptions m
- supervisorSpec :: Monad m => SupervisorName -> (SupervisorOptions m -> SupervisorOptions m) -> ProcessSpec m
- supervisorSpecWithDefaults :: Monad m => SupervisorName -> ProcessSpec m
- workerSpec :: Monad m => WorkerName -> m () -> (WorkerOptions m -> WorkerOptions m) -> ProcessSpec m
- workerSpec1 :: Monad m => WorkerName -> (WorkerId -> m ()) -> (WorkerOptions m -> WorkerOptions m) -> ProcessSpec m
- workerSpecWithDefaults :: Monad m => WorkerName -> m () -> ProcessSpec m
- buildSupervisorOptions :: Monad m => SupervisorName -> (SupervisorOptions m -> SupervisorOptions m) -> SupervisorOptions m
- buildSupervisorOptionsWithDefaults :: Monad m => SupervisorName -> SupervisorOptions m
- buildWorkerOptions :: Monad m => WorkerName -> m () -> (WorkerOptions m -> WorkerOptions m) -> WorkerOptions m
- buildWorkerOptions1 :: Monad m => WorkerName -> (WorkerId -> m ()) -> (WorkerOptions m -> WorkerOptions m) -> WorkerOptions m
- buildWorkerOptionsWithDefaults :: Monad m => WorkerName -> m () -> WorkerOptions m
- getMaskingState :: MonadIO m => m MaskingState
- unsafeTry :: (Exception e, MonadUnliftIO m) => m a -> m (Either e a)
- fromAnyException :: Exception e => SomeException -> Maybe e
Documentation
type SupervisorId = UUID Source #
type WorkerAction m = WorkerId -> m () Source #
type ProcessName = Text Source #
type CapatazName = Text Source #
type SupervisorName = Text Source #
type WorkerName = Text Source #
type RestartCount = Int Source #
type ParentSupervisor = Supervisor Source #
newtype ProcessThreadId Source #
Wrapper for ThreadId
Since: 0.2.0.0
Instances
data CapatazEvent Source #
Event delivered to the CapatazOptions
callback sub-routine; these events can
be used to monitor the capataz system and track what is doing, providing high
levels of telemetry for all supervisors and workers of a capataz system,
ergo, should be used for logging, monitoring and testing purposes.
Since: 0.1.0.0
Instances
data WorkerTerminationPolicy Source #
Defines how a Worker
process termination should be handled by its
supervisor.
Since: 0.0.0.0
Infinity | Supervisor waits until infinity for the worker termination callback to finish execution. |
BrutalTermination | Supervisor terminates worker process without a chance to call its termination callback. |
TimeoutMillis !Int | Supervisor allows a number of milliseconds for worker termination callback complete, if not completed by specified milliseconds the termination is cancelled via a BrutalTermination signal. |
Instances
defWorkerTerminationPolicy :: WorkerTerminationPolicy Source #
Default worker termination is a timeout of three (3) seconds.
Since: 0.2.0.0
data ProcessRestartAction Source #
Internal helper record that assesses if a Supervisor error intensity has been breached.
ResetRestartCount | Indicates a Supervisor to restart a failed process _and_ reset the restart count given this Supervisor's intensity period timeout has passed. |
IncreaseRestartCount | Indicates a Supervisor to restart the failed process _and_ increase the restart count (normal operation) of the supervised process. |
HaltSupervisor | Indicates a Supervisor stop executing given the error intensity has been breached. |
Instances
data ProcessTerminationOrder Source #
Specifies the order in which supervised process should be terminated by a Supervisor in case of a restart or shutdown.
Since: 0.0.0.0
NewestFirst | Supervisor terminates supervised process from most recent to oldest. |
OldestFirst | Supervisor terminates supervised process from oldest to most recent. |
Instances
defProcessTerminationOrder :: ProcessTerminationOrder Source #
Default termination order is OldestFirst
.
Since: 0.2.0.0
data SupervisorRestartStrategy Source #
Specifies how a Supervisor restarts a failing process.
Since: 0.0.0.0
AllForOne | Supervisor terminates all sibling supervised processes that didn't fail, and then restarts all of them together. This strategy serves best when all processes depend upon each other. |
OneForOne | Supervisor only restarts the supervised process that failed. |
Instances
defSupervisorRestartStategy :: SupervisorRestartStrategy Source #
Default restart strategy is OneForOne
.
Since: 0.2.0.0
data CapatazOptions m Source #
Allows to:
- Specify options for the root
Supervisor
of a capataz system. - Provide a
CapatazOptions
callback to monitor or log a capataz system.
Since: 0.1.0.0
CapatazOptions | |
|
Instances
data WorkerRestartStrategy Source #
Specifies how a Supervisor deals with the lifecycle of worker process in case of completion without errors and failure.
Permanent | Supervisor will always restart a worker process, in both completion and failure scenarios. |
Transient | Supervisor will only restart worker process if it has a failure in execution. |
Temporary | Supervisor will never restart a worker, even on failure. |
Instances
defWorkerRestartStrategy :: WorkerRestartStrategy Source #
A worker default restart strategy is Transient.
data WorkerOptions m Source #
Specifies all options that can be used to create a Worker Process. You may
create a record of this type via the smart constructor buildWorkerOptions
.
Since: 0.1.0.0
WorkerOptions | |
|
Instances
Record that contains the Async record (thread reference) of a worker
Since: 0.1.0.0
Worker | |
|
data ProcessEnv Source #
ProcessEnv | |
|
data SupervisorOptions m Source #
SupervisorOptions | |
|
Instances
data Supervisor m Source #
Supervisor | |
|
Instances
HasSupervisor Supervisor Source # | |
Defined in Control.Concurrent.Capataz.Internal.Core getSupervisor :: Supervisor m -> Supervisor m Source # |
data ControlAction m Source #
Internal record that represents an action being sent from threads using the Capataz public API.
ForkWorker | |
| |
ForkSupervisor | |
| |
TerminateProcess | |
|
Instances
data CapatazSignal Source #
Internal exception thrown to the Capataz loop to indicate termination of execution
Instances
data CapatazError Source #
Internal exception triggered when a Worker violates error intensity specification
SupervisorIntensityReached | |
|
Instances
data CallbackType Source #
Internal record that indicates what type of callback function is being invoked; this is used for telemetry purposes
Instances
data ProcessType Source #
Instances
Eq ProcessType Source # | |
Defined in Control.Concurrent.Capataz.Internal.Types (==) :: ProcessType -> ProcessType -> Bool # (/=) :: ProcessType -> ProcessType -> Bool # | |
Show ProcessType Source # | |
Defined in Control.Concurrent.Capataz.Internal.Types showsPrec :: Int -> ProcessType -> ShowS # show :: ProcessType -> String # showList :: [ProcessType] -> ShowS # | |
Pretty ProcessType Source # | |
Defined in Control.Concurrent.Capataz.Internal.Types pretty :: ProcessType -> Doc ann # prettyList :: [ProcessType] -> Doc ann # |
data ProcessError Source #
Internal exception triggered when a callback of a Worker fails
Instances
data MonitorEvent Source #
Internal event delivered from Worker threads to the Capataz thread to indicate completion, failure or termination
Instances
Show MonitorEvent Source # | |
Defined in Control.Concurrent.Capataz.Internal.Types showsPrec :: Int -> MonitorEvent -> ShowS # show :: MonitorEvent -> String # showList :: [MonitorEvent] -> ShowS # |
data SupervisorStatus Source #
Internal record used as a state machine, indicating the state of a supervisor process
Initializing | This state is set when the process is created and it starts spawning its static process list. |
Running | This state is set when the supervisor process starts listenting to both ControlAction and MonitorEvent messages. |
Halting | This state is set when the supervisor process is terminating it's assigned worker |
Halted | This state is set when the supervisor process is finished |
Instances
data SupervisorMessage m Source #
Internal message delivered to a supervisor process that can either be a call from public API or an event from its monitored worker process.
ControlAction !(ControlAction m) | Represents a request from done to the supervisor thread from another thread using the public API |
MonitorEvent !MonitorEvent | Represents an event (failure, completion, etc) from a monitored worker process to the supervisor |
Instances
Generic (SupervisorMessage m) Source # | |
Defined in Control.Concurrent.Capataz.Internal.Types type Rep (SupervisorMessage m) :: Type -> Type # from :: SupervisorMessage m -> Rep (SupervisorMessage m) x # to :: Rep (SupervisorMessage m) x -> SupervisorMessage m # | |
type Rep (SupervisorMessage m) Source # | |
Defined in Control.Concurrent.Capataz.Internal.Types type Rep (SupervisorMessage m) = D1 (MetaData "SupervisorMessage" "Control.Concurrent.Capataz.Internal.Types" "capataz-0.2.1.0-Fs9ChgJx0VFLAFPvWeRfkG" False) (C1 (MetaCons "ControlAction" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (ControlAction m))) :+: C1 (MetaCons "MonitorEvent" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 MonitorEvent))) |
Internal Type to manage both Worker
and Supervisor
processes
Since: 0.1.0.0
WorkerProcess !(Worker m) | |
SupervisorProcess !(Supervisor m) |
data ProcessSpec m Source #
Record used to specify how to build a runtime Process
in a static
supervision tree; to create values of this type, you must use:
workerSpec
orworkerSpecWithDefaults
to build a worker processsupervisorSpec
orsupervisorSpecWithDefaults
to build a supervisor process
Since: 0.1.0.0
Record that contains the environment of a capataz monitor, this is used as the main record to create workers and to stop the supervisor thread.
Since: 0.0.0.0
Capataz | |
|
Instances
HasSupervisor Capataz Source # | |
Defined in Control.Concurrent.Capataz.Internal.Core getSupervisor :: Capataz m -> Supervisor m Source # | |
HasTeardown (Capataz m) Source # | |
Defined in Control.Concurrent.Capataz.Internal.Types getTeardown :: Capataz m -> Teardown # |
data ParentSupervisorEnv m Source #
Internal utility record used to hold part of the runtime information of a supervisor that acts as a parent of another supervisor.
ParentSupervisorEnv | |
|
data SupervisorEnv m Source #
Convenience internal utility record that contains all values related to a supervisor process.
SupervisorEnv | |
|
:: Monad m | |
=> Text | |
-> (CapatazOptions m -> CapatazOptions m) | Function to modify root supervisor |
-> CapatazOptions m |
Builds a CapatazOptions
record with defaults on how to create a capataz
root supervisor, these defaults are:
- Intensity error tolerance is set to 1 error every 5 seconds
- A
SupervisorRestartStrategy
ofOneForOne
- A
ProcessTerminationOrder
ofOldestFirst
This function is intended to be used in combination with forkCapataz
.
Since: 0.1.0.0
:: Monad m | |
=> SupervisorName | Name used for telemetry purposes |
-> (SupervisorOptions m -> SupervisorOptions m) |
|
-> ProcessSpec m |
Builds a ProcessSpec
record for a supervisor process with defaults from
supervisorSpecWithDefaults
. This function allows overrides of these
defaults using lenses.
This function is used when building a supervisor branch in a static supervision trees.
Since: 0.1.0.0
supervisorSpecWithDefaults Source #
:: Monad m | |
=> SupervisorName | Name used for telemetry purposes |
-> ProcessSpec m |
Builds a ProcessSpec
record for a supervisor process with defaults from
buildSupervisorOptionsWithDefaults
.
This function is used when building a supervisor branch in a static supervision trees.
Since: 0.1.0.0
:: Monad m | |
=> WorkerName | Name used for telemetry purposes |
-> m () |
|
-> (WorkerOptions m -> WorkerOptions m) | Function to modify default worker options |
-> ProcessSpec m |
Builds a ProcessSpec
record for a worker process with defaults from
workerSpecWithDefaults
. This function allows overrides of these
defaults using lenses.
This function is used when building a worker in a static supervision tree.
Since: 0.1.0.0
:: Monad m | |
=> WorkerName | Name used for telemetry purposes |
-> (WorkerId -> m ()) | sub-routine to be supervised |
-> (WorkerOptions m -> WorkerOptions m) | Function to modify default worker options |
-> ProcessSpec m |
Builds a ProcessSpec
record for a worker process with defaults from
workerSpecWithDefaults
. This function allows overrides of these
defaults using lenses.
This function is used when building a worker in a static supervision tree.
The given sub-routine will receive the WorkerId
as a parameter
Since: 0.2.0.0
workerSpecWithDefaults Source #
:: Monad m | |
=> WorkerName | Name used for telemetry purposes |
-> m () | IO sub-routine to be supervised |
-> ProcessSpec m |
Builds a ProcessSpec
record for a worker process with defaults from
buildSupervisorOptionsWithDefaults
.
This function is used when building a worker in a static supervision tree.
Since: 0.1.0.0
buildSupervisorOptions Source #
:: Monad m | |
=> SupervisorName | Name used for telemetry purposes |
-> (SupervisorOptions m -> SupervisorOptions m) | Function to modify default supervisor options |
-> SupervisorOptions m |
Builds a SupervisorOptions
record with defaults from
buildSupervisorOptionsWithDefaults
. This function allows overrides of these
defaults using lenses.
This function is intended to be used in combination with forkSupervisor
.
Since: 0.1.0.0
buildSupervisorOptionsWithDefaults Source #
:: Monad m | |
=> SupervisorName | Name used for telemetry purposes |
-> SupervisorOptions m |
Builds a SupervisorOptions
record with defaults to create a supervisor
process, these defaults are:
- Intensity error tolerance is set to 1 error every 5 seconds
- A
SupervisorRestartStrategy
ofOneForOne
- A
ProcessTerminationOrder
ofOldestFirst
This function is intended to be used in combination with forkSupervisor
.
Since: 0.1.0.0
:: Monad m | |
=> WorkerName | Name used for telemetry purposes |
-> m () | Process sub-routine to be supervised |
-> (WorkerOptions m -> WorkerOptions m) | Function to modify default worker options |
-> WorkerOptions m |
Builds a WorkerOptions
record, keeps the defaults from
buildWorkerOptionsWithDefaults
but allows overrides using lenses.
This function is intended to be used in combination with forkWorker
. See the
capataz-simple-example project in the examples directory for a demonstration.
Since: 0.1.0.0
:: Monad m | |
=> WorkerName | Name used for telemetry purposes |
-> (WorkerId -> m ()) | Process sub-routine to be supervised |
-> (WorkerOptions m -> WorkerOptions m) | Function to modify default worker options |
-> WorkerOptions m |
Builds a WorkerOptions
record, keeps the defaults from
buildWorkerOptionsWithDefaults
but allows overrides using lenses.
This function is intended to be used in combination with forkWorker
. See the
capataz-simple-example project in the examples directory for a demonstration.
The given sub-routine will receive the WorkerId
as a parameter.
Since: 0.2.0.0
buildWorkerOptionsWithDefaults Source #
:: Monad m | |
=> WorkerName | Name used for telemetry purposes |
-> m () |
|
-> WorkerOptions m |
Builds a WorkerOptions
record with defaults to create a worker process,
the defaults are:
- A
Transient
WorkerRestartStrategy
- A
WorkerTerminationPolicy
of a 3 seconds timeout - A _completion_ callback that just returns unit
- A _termination_ callback that just returns unit
- A _failure_ callback that just returns unit
This function is intended to be used in combination with forkWorker
, for creating a
worker in an static supervision tree, use workerSpecWithDefaults
instead. See the
capataz-simple-example project in the examples directory for a demonstration.
Since: 0.1.0.0
getMaskingState :: MonadIO m => m MaskingState Source #
Used for debugging purposes
unsafeTry :: (Exception e, MonadUnliftIO m) => m a -> m (Either e a) Source #
Given we want to capture async exceptions to send them back to a supervisor and we are running on masked states, we need to have a try that catches all kinds of exceptions
fromAnyException :: Exception e => SomeException -> Maybe e Source #
Given unliftio wraps exceptions in 3 layers of Exceptions, and we are using vanilla exceptions, we need to make sure that we account for all different exception types