Safe Haskell | None |
---|---|
Language | Haskell2010 |
Control.Concurrent.Capataz.Internal.Types
Description
This module contains all the types used across all the other modules
- type CapatazId = UUID
- type WorkerId = UUID
- type SupervisorId = UUID
- type ProcessId = UUID
- type WorkerAction = IO ()
- type ProcessThreadId = ThreadId
- type ProcessName = Text
- type CapatazName = Text
- type SupervisorName = Text
- type WorkerName = Text
- type RestartCount = Int
- type ProcessMap = HashMap ProcessId Process
- type ParentSupervisor = Supervisor
- data CapatazEvent
- = InvalidSupervisorStatusReached { }
- | SupervisorStatusChanged { }
- | ProcessTerminated { }
- | ProcessStarted { }
- | ProcessRestarted { }
- | ProcessCompleted { }
- | ProcessFailed { }
- | ProcessCallbackExecuted { }
- | ProcessTerminationStarted { }
- | ProcessTerminationFinished { }
- | CapatazFailed { }
- | CapatazTerminated { }
- data WorkerTerminationPolicy
- data ProcessRestartAction
- data ProcessTerminationOrder
- data SupervisorRestartStrategy
- data CapatazOptions = CapatazOptions {
- supervisorIntensity :: !Int
- supervisorPeriodSeconds :: !NominalDiffTime
- supervisorRestartStrategy :: !SupervisorRestartStrategy
- supervisorProcessSpecList :: ![ProcessSpec]
- supervisorProcessTerminationOrder :: !ProcessTerminationOrder
- supervisorOnIntensityReached :: !(IO ())
- supervisorOnFailure :: !(SomeException -> IO ())
- notifyEvent :: !(CapatazEvent -> IO ())
- data WorkerRestartStrategy
- data WorkerOptions = WorkerOptions {
- workerAction :: WorkerAction
- workerName :: !WorkerName
- workerOnFailure :: !(SomeException -> IO ())
- workerOnCompletion :: !(IO ())
- workerOnTermination :: !(IO ())
- workerTerminationPolicy :: !WorkerTerminationPolicy
- workerRestartStrategy :: !WorkerRestartStrategy
- data Worker = Worker {
- workerId :: !WorkerId
- workerAsync :: !(Async ())
- workerCreationTime :: !UTCTime
- workerName :: !WorkerName
- workerOptions :: !WorkerOptions
- data ProcessEnv = ProcessEnv {}
- data SupervisorOptions = SupervisorOptions {
- supervisorName :: Text
- supervisorIntensity :: !Int
- supervisorPeriodSeconds :: !NominalDiffTime
- supervisorRestartStrategy :: !SupervisorRestartStrategy
- supervisorProcessSpecList :: ![ProcessSpec]
- supervisorProcessTerminationOrder :: !ProcessTerminationOrder
- supervisorOnIntensityReached :: !(IO ())
- supervisorOnFailure :: !(SomeException -> IO ())
- data Supervisor = Supervisor {}
- data ControlAction
- = ForkWorker {
- workerOptions :: !WorkerOptions
- returnWorkerId :: !(WorkerId -> IO ())
- | ForkSupervisor {
- supervisorOptions :: !SupervisorOptions
- returnSupervisor :: !(Supervisor -> IO ())
- | TerminateProcess {
- processId :: !ProcessId
- processTerminationReason :: !Text
- notifyProcessTermination :: !(Bool -> IO ())
- = 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
- data Process
- data ProcessSpec
- data Capataz = Capataz {}
- data ParentSupervisorEnv = ParentSupervisorEnv {
- supervisorId :: !SupervisorId
- supervisorName :: !SupervisorName
- supervisorNotify :: !(SupervisorMessage -> IO ())
- notifyEvent :: !(CapatazEvent -> IO ())
- data SupervisorEnv = SupervisorEnv {
- supervisorId :: !SupervisorId
- supervisorName :: !SupervisorName
- supervisorNotify :: !(SupervisorMessage -> IO ())
- supervisorGetNotification :: !(STM SupervisorMessage)
- supervisorProcessMap :: !(IORef ProcessMap)
- supervisorStatusVar :: !(TVar SupervisorStatus)
- supervisorOptions :: !SupervisorOptions
- supervisorIntensity :: !Int
- supervisorPeriodSeconds :: !NominalDiffTime
- supervisorRestartStrategy :: !SupervisorRestartStrategy
- supervisorProcessTerminationOrder :: !ProcessTerminationOrder
- supervisorOnIntensityReached :: !(IO ())
- supervisorOnIntensityReached :: !(SomeException -> IO ())
- notifyEvent :: !(CapatazEvent -> IO ())
- defCapatazOptions :: (CapatazOptions -> CapatazOptions) -> CapatazOptions
- supervisorSpec :: SupervisorName -> (SupervisorOptions -> SupervisorOptions) -> ProcessSpec
- supervisorSpecWithDefaults :: SupervisorName -> ProcessSpec
- workerSpec :: WorkerName -> IO () -> (WorkerOptions -> WorkerOptions) -> ProcessSpec
- workerSpecWithDefaults :: WorkerName -> IO () -> ProcessSpec
- buildSupervisorOptions :: SupervisorName -> (SupervisorOptions -> SupervisorOptions) -> SupervisorOptions
- buildSupervisorOptionsWithDefaults :: SupervisorName -> SupervisorOptions
- buildWorkerOptions :: WorkerName -> IO () -> (WorkerOptions -> WorkerOptions) -> WorkerOptions
- buildWorkerOptionsWithDefaults :: WorkerName -> IO () -> WorkerOptions
Documentation
type SupervisorId = UUID Source #
type WorkerAction = IO () Source #
type ProcessThreadId = ThreadId 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 #
data CapatazEvent Source #
Event delivered to the "notifyEvent" 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.
Constructors
Instances
data WorkerTerminationPolicy Source #
Defines how a Worker process termination should be handled by its supervisor.
Constructors
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. |
data ProcessRestartAction Source #
Internal helper record that assesses if a Supervisor error intensity has been breached.
Constructors
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. |
data ProcessTerminationOrder Source #
Specifies the order in which supervised process should be terminated by a Supervisor in case of a restart or shutdown.
Constructors
NewestFirst | Supervisor terminates supervised process from most recent to oldest. |
OldestFirst | Supervisor terminates supervised process from oldest to most recent. |
data SupervisorRestartStrategy Source #
Specifies how a Supervisor restarts a failing process.
data CapatazOptions Source #
Allows to:
- Specify options for The root supervisor of a capataz system.
- Provie a "notifyEvent" callback to monitor or log a capataz system.
Constructors
CapatazOptions | |
Fields
|
Instances
data WorkerRestartStrategy Source #
Specifies how a Supervisor deals with the lifecycle of worker process in case of completion without errors and failure.
data WorkerOptions 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".
Constructors
WorkerOptions | |
Fields
|
Instances
Record that contains the Async record (thread reference) of a worker
Constructors
Worker | |
Fields
|
data ProcessEnv Source #
Constructors
ProcessEnv | |
Fields
|
data SupervisorOptions Source #
Constructors
SupervisorOptions | |
Fields
|
Instances
data Supervisor Source #
Constructors
Supervisor | |
Fields
|
Instances
data ControlAction Source #
Internal record that represents an action being sent from threads using the Capataz public API.
Constructors
ForkWorker | |
Fields
| |
ForkSupervisor | |
Fields
| |
TerminateProcess | |
Fields
|
Instances
data CapatazSignal Source #
Internal exception thrown to the Capataz loop to indicate termination of execution
Constructors
CapatazFailure | |
RestartProcessException | |
TerminateProcessException | |
Fields | |
BrutallyTerminateProcessException | |
Fields |
Instances
data CapatazError Source #
Internal exception triggered when a Worker violates error intensity specification
Constructors
SupervisorIntensityReached | |
Fields
|
Instances
data CallbackType Source #
Internal record that indicates what type of callback function is being invoked; this is used for telemetry purposes
Constructors
OnCompletion | |
OnFailure | |
OnTermination |
Instances
data ProcessError Source #
Internal exception triggered when a callback of a Worker fails
Constructors
ProcessCallbackFailed | |
Fields |
Instances
data MonitorEvent Source #
Internal event delivered from Worker threads to the Capataz thread to indicate completion, failure or termination
Constructors
ProcessTerminated' | |
Fields | |
ProcessFailed' | |
Fields | |
ProcessCompleted' | |
Fields
| |
ProcessForcedRestart | |
Fields
|
Instances
data SupervisorStatus Source #
Internal record used as a state machine, indicating the state of a supervisor process
Constructors
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 |
data SupervisorMessage 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.
Constructors
ControlAction !ControlAction | 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
Internal Type to manage both Worker and Supervisor processes
Constructors
WorkerProcess Worker | |
SupervisorProcess Supervisor |
data ProcessSpec 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" or "workerSpecWithDefaults" to build a worker process
- "supervisorSpec" or "supervisorSpecWithDefaults" to build a supervisor process
Constructors
WorkerSpec WorkerOptions | |
SupervisorSpec SupervisorOptions |
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.
Constructors
Capataz | |
Fields |
data ParentSupervisorEnv Source #
Internal utility record used to hold part of the runtime information of a supervisor that acts as a parent of another supervisor.
Constructors
ParentSupervisorEnv | |
Fields
|
data SupervisorEnv Source #
Convenience internal utility record that contains all values related to a supervisor process.
Constructors
SupervisorEnv | |
Fields
|
Arguments
:: (CapatazOptions -> CapatazOptions) | Function to modify root supervisor options |
-> CapatazOptions |
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 of OneForOne
- A ProcessTerminationOrder of OldestFirst
This function is intended to be used in combination with "forkCapataz".
Arguments
:: SupervisorName | Name used for telemetry purposes |
-> (SupervisorOptions -> SupervisorOptions) | Function to modify default supervisor options |
-> ProcessSpec |
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.
supervisorSpecWithDefaults Source #
Arguments
:: SupervisorName | Name used for telemetry purposes |
-> ProcessSpec |
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.
Arguments
:: WorkerName | Name used for telemetry purposes |
-> IO () | IO sub-routine to be supervised |
-> (WorkerOptions -> WorkerOptions) | Function to modify default worker options |
-> ProcessSpec |
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.
workerSpecWithDefaults Source #
Arguments
:: WorkerName | Name used for telemetry purposes |
-> IO () | IO sub-routine to be supervised |
-> ProcessSpec |
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.
buildSupervisorOptions Source #
Arguments
:: SupervisorName | Name used for telemetry purposes |
-> (SupervisorOptions -> SupervisorOptions) | Function to modify default supervisor options |
-> SupervisorOptions |
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".
buildSupervisorOptionsWithDefaults Source #
Arguments
:: SupervisorName | Name used for telemetry purposes |
-> SupervisorOptions |
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 of OneForOne
- A ProcessTerminationOrder of OldestFirst
This function is intended to be used in combination with "forkSupervisor".
Arguments
:: WorkerName | Name used for telemetry purposes |
-> IO () | IO sub-routine to be supervised |
-> (WorkerOptions -> WorkerOptions) | Function to modify default worker options |
-> WorkerOptions |
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 ... example in the examples directory for a demonstration.
buildWorkerOptionsWithDefaults Source #
Arguments
:: WorkerName | Name used for telemetry purposes |
-> IO () | IO sub-routine to be supervised |
-> WorkerOptions |
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 ... example for a demonstration.