-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | OTP-like supervision trees in Haskell
--   
--   <a>capataz</a> enhances the reliability of your concurrent
--   applications by offering supervision of green threads that run in your
--   application.
--   
--   Advantages over standard library:
--   
--   <ul>
--   <li>Links related long-living processes together under a common
--   capataz supervisor, with restart/shutdown order</li>
--   <li>Set restart strategies (Permanent, Transient, Temporary) on
--   <a>IO</a> sub-routines on a granular level</li>
--   <li>Set restart strategies on a pool of long-living worker threads
--   (AllForOne, OneForOne)</li>
--   <li>Complete telemetry on the sub-routine lifecycle of your
--   application (start, error, restarts, shutdown)</li>
--   </ul>
@package capataz
@version 0.2.0.0


-- | This module contains all the types used across all the other modules
module Control.Concurrent.Capataz.Internal.Types
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

-- | Wrapper for <a>ThreadId</a>
newtype ProcessThreadId
PTID :: ThreadId -> ProcessThreadId

-- | Event delivered to the <a>$sel:notifyEvent:ParentSupervisorEnv</a>
--   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.
data CapatazEvent
InvalidSupervisorStatusReached :: !SupervisorId -> !SupervisorName -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
SupervisorStatusChanged :: !SupervisorId -> !SupervisorName -> !SupervisorStatus -> !SupervisorStatus -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:prevSupervisorStatus:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorStatus
[$sel:newSupervisorStatus:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorStatus
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessTerminated :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !Text -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:terminationReason:InvalidSupervisorStatusReached] :: CapatazEvent -> !Text
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessStarted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessRestarted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !Int -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:processRestartCount:InvalidSupervisorStatusReached] :: CapatazEvent -> !Int
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessCompleted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessFailed :: !SupervisorName -> !SupervisorId -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !SomeException -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:processError:InvalidSupervisorStatusReached] :: CapatazEvent -> !SomeException
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessCallbackExecuted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !(Maybe SomeException) -> !CallbackType -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:processCallbackError:InvalidSupervisorStatusReached] :: CapatazEvent -> !(Maybe SomeException)
[$sel:processCallbackType:InvalidSupervisorStatusReached] :: CapatazEvent -> !CallbackType
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessTerminationStarted :: !SupervisorName -> !SupervisorId -> !Text -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:terminationReason:InvalidSupervisorStatusReached] :: CapatazEvent -> !Text
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessTerminationFinished :: !SupervisorName -> !SupervisorId -> !Text -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:terminationReason:InvalidSupervisorStatusReached] :: CapatazEvent -> !Text
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
CapatazFailed :: !SupervisorId -> !SupervisorName -> !SomeException -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorError:InvalidSupervisorStatusReached] :: CapatazEvent -> !SomeException
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
CapatazTerminated :: !SupervisorName -> !SupervisorId -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime

-- | Defines how a <a>Worker</a> process termination should be handled by
--   its supervisor.
data WorkerTerminationPolicy

-- | Supervisor waits until infinity for the worker termination callback to
--   finish execution.
Infinity :: WorkerTerminationPolicy

-- | Supervisor terminates worker process without a chance to call its
--   termination callback.
BrutalTermination :: WorkerTerminationPolicy

-- | Supervisor allows a number of milliseconds for worker termination
--   callback complete, if not completed by specified milliseconds the
--   termination is cancelled via a <a>BrutalTermination</a> signal.
TimeoutMillis :: !Int -> WorkerTerminationPolicy

-- | Default worker termination is a timeout of three (3) seconds.
defWorkerTerminationPolicy :: WorkerTerminationPolicy

-- | Internal helper record that assesses if a Supervisor error intensity
--   has been breached.
data ProcessRestartAction

-- | Indicates a Supervisor to restart a failed process _and_ reset the
--   restart count given this Supervisor's intensity period timeout has
--   passed.
ResetRestartCount :: ProcessRestartAction

-- | Indicates a Supervisor to restart the failed process _and_ increase
--   the restart count (normal operation) of the supervised process.
IncreaseRestartCount :: ProcessRestartAction

-- | Indicates a Supervisor stop executing given the error intensity has
--   been breached.
HaltSupervisor :: ProcessRestartAction

-- | Specifies the order in which supervised process should be terminated
--   by a Supervisor in case of a restart or shutdown.
data ProcessTerminationOrder

-- | Supervisor terminates supervised process from most recent to oldest.
NewestFirst :: ProcessTerminationOrder

-- | Supervisor terminates supervised process from oldest to most recent.
OldestFirst :: ProcessTerminationOrder

-- | Default termination order is <a>OldestFirst</a>.
defProcessTerminationOrder :: ProcessTerminationOrder

-- | Specifies how a Supervisor restarts a failing process.
data SupervisorRestartStrategy

-- | 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.
AllForOne :: SupervisorRestartStrategy

-- | Supervisor only restarts the supervised process that failed.
OneForOne :: SupervisorRestartStrategy

-- | Default restart strategy is <a>OneForOne</a>.
defSupervisorRestartStategy :: SupervisorRestartStrategy

-- | Allows to:
--   
--   <ul>
--   <li>Specify options for the root <a>Supervisor</a> of a capataz
--   system.</li>
--   <li>Provide a <a>$sel:notifyEvent:ParentSupervisorEnv</a> callback to
--   monitor or log a capataz system.</li>
--   </ul>
data CapatazOptions m
CapatazOptions :: !SupervisorName -> !Int -> !NominalDiffTime -> !SupervisorRestartStrategy -> ![ProcessSpec m] -> !ProcessTerminationOrder -> !(m ()) -> !(SomeException -> m ()) -> !(CapatazEvent -> m ()) -> CapatazOptions m
[$sel:supervisorName:CapatazOptions] :: CapatazOptions m -> !SupervisorName
[$sel:supervisorIntensity:CapatazOptions] :: CapatazOptions m -> !Int
[$sel:supervisorPeriodSeconds:CapatazOptions] :: CapatazOptions m -> !NominalDiffTime
[$sel:supervisorRestartStrategy:CapatazOptions] :: CapatazOptions m -> !SupervisorRestartStrategy
[$sel:supervisorProcessSpecList:CapatazOptions] :: CapatazOptions m -> ![ProcessSpec m]
[$sel:supervisorProcessTerminationOrder:CapatazOptions] :: CapatazOptions m -> !ProcessTerminationOrder
[$sel:supervisorOnIntensityReached:CapatazOptions] :: CapatazOptions m -> !(m ())

-- | Callback sub-routine that gets executed when the root supervisor
--   fails.
[$sel:supervisorOnFailure:CapatazOptions] :: CapatazOptions m -> !(SomeException -> m ())

-- | Callback used for telemetry purposes.
[$sel:notifyEvent:CapatazOptions] :: CapatazOptions m -> !(CapatazEvent -> m ())

-- | Specifies how a Supervisor deals with the lifecycle of worker process
--   in case of completion without errors and failure.
data WorkerRestartStrategy

-- | Supervisor will <b>always</b> restart a worker process, in both
--   completion and failure scenarios.
Permanent :: WorkerRestartStrategy

-- | Supervisor will <b>only</b> restart worker process if it has a failure
--   in execution.
Transient :: WorkerRestartStrategy

-- | Supervisor will <b>never</b> restart a worker, even on failure.
Temporary :: WorkerRestartStrategy

-- | A worker default restart strategy is <a>Transient</a>.
defWorkerRestartStrategy :: WorkerRestartStrategy

-- | Specifies all options that can be used to create a Worker Process. You
--   may create a record of this type via the smart constructor
--   <a>buildWorkerOptions</a>.
data WorkerOptions m
WorkerOptions :: WorkerAction m -> !WorkerName -> !(SomeException -> m ()) -> !(m ()) -> !(m ()) -> !WorkerTerminationPolicy -> !WorkerRestartStrategy -> WorkerOptions m

-- | An <tt>IO ()</tt> sub-routine that will be executed when the worker
--   thread is created, this attribute is lazy given we want to this value
--   on a worker thread environment.
[$sel:workerAction:WorkerOptions] :: WorkerOptions m -> WorkerAction m

-- | Name of the Worker (present on <a>CapatazEvent</a> records)
[$sel:workerName:WorkerOptions] :: WorkerOptions m -> !WorkerName

-- | Callback used when the worker fails with an error
[$sel:workerOnFailure:WorkerOptions] :: WorkerOptions m -> !(SomeException -> m ())

-- | Callback used when the worker completes execution without error
[$sel:workerOnCompletion:WorkerOptions] :: WorkerOptions m -> !(m ())

-- | Callback used when the worker is terminated
[$sel:workerOnTermination:WorkerOptions] :: WorkerOptions m -> !(m ())

-- | Indicates how a worker should be terminated
[$sel:workerTerminationPolicy:WorkerOptions] :: WorkerOptions m -> !WorkerTerminationPolicy

-- | Indicates how a worker should be restarted
[$sel:workerRestartStrategy:WorkerOptions] :: WorkerOptions m -> !WorkerRestartStrategy

-- | Record that contains the <a>Async</a> record (thread reference) of a
--   worker
data Worker m
Worker :: !WorkerId -> !(Async ()) -> !UTCTime -> !WorkerName -> !(WorkerOptions m) -> Worker m

-- | Unique identifier for a worker that is executing
[$sel:workerId:Worker] :: Worker m -> !WorkerId

-- | <a>Async</a> thread of a worker, this Async executes the <tt>IO
--   ()</tt> sub-routine
[$sel:workerAsync:Worker] :: Worker m -> !(Async ())

-- | Time where this worker was created (used for error intensity checks)
[$sel:workerCreationTime:Worker] :: Worker m -> !UTCTime

-- | Name of the Worker (present on <a>CapatazEvent</a> records)
[$sel:workerName:Worker] :: Worker m -> !WorkerName

-- | <a>WorkerOptions</a> contains all the options around restart and
--   termination policies
[$sel:workerOptions:Worker] :: Worker m -> !(WorkerOptions m)
data ProcessEnv
ProcessEnv :: !ProcessId -> !ProcessName -> !(Async ()) -> !UTCTime -> !WorkerRestartStrategy -> ProcessEnv
[$sel:processId:ProcessEnv] :: ProcessEnv -> !ProcessId
[$sel:processName:ProcessEnv] :: ProcessEnv -> !ProcessName
[$sel:processAsync:ProcessEnv] :: ProcessEnv -> !(Async ())
[$sel:processCreationTime:ProcessEnv] :: ProcessEnv -> !UTCTime
[$sel:processRestartStrategy:ProcessEnv] :: ProcessEnv -> !WorkerRestartStrategy
data SupervisorOptions m
SupervisorOptions :: Text -> !Int -> !NominalDiffTime -> !SupervisorRestartStrategy -> ![ProcessSpec m] -> !ProcessTerminationOrder -> !(m ()) -> !(SomeException -> m ()) -> SupervisorOptions m

-- | Name of the Supervisor (present on <a>CapatazEvent</a> records)
[$sel:supervisorName:SupervisorOptions] :: SupervisorOptions m -> Text

-- | How many errors is the Supervisor be able to handle; check:
--   <a>http://erlang.org/doc/design_principles/sup_princ.html#max_intensity</a>
[$sel:supervisorIntensity:SupervisorOptions] :: SupervisorOptions m -> !Int

-- | Period of time where the Supervisor can receive "supervisorIntensity"
--   amount of errors
[$sel:supervisorPeriodSeconds:SupervisorOptions] :: SupervisorOptions m -> !NominalDiffTime

-- | What is the <a>SupervisorRestartStrategy</a> for this Capataz
[$sel:supervisorRestartStrategy:SupervisorOptions] :: SupervisorOptions m -> !SupervisorRestartStrategy

-- | Static set of workers that start as soon as the <a>Capataz</a> is
--   created
[$sel:supervisorProcessSpecList:SupervisorOptions] :: SupervisorOptions m -> ![ProcessSpec m]

-- | In which order the <a>Supervisor</a> record is going to terminate it's
--   workers
[$sel:supervisorProcessTerminationOrder:SupervisorOptions] :: SupervisorOptions m -> !ProcessTerminationOrder

-- | Callback used when the error intensity is reached
[$sel:supervisorOnIntensityReached:SupervisorOptions] :: SupervisorOptions m -> !(m ())
[$sel:supervisorOnFailure:SupervisorOptions] :: SupervisorOptions m -> !(SomeException -> m ())
data Supervisor m
Supervisor :: !SupervisorId -> !SupervisorName -> !(SupervisorOptions m) -> !UTCTime -> !(Async ()) -> SupervisorMessage m -> m () -> !(SupervisorEnv m) -> Supervisor m
[$sel:supervisorId:Supervisor] :: Supervisor m -> !SupervisorId
[$sel:supervisorName:Supervisor] :: Supervisor m -> !SupervisorName
[$sel:supervisorOptions:Supervisor] :: Supervisor m -> !(SupervisorOptions m)
[$sel:supervisorCreationTime:Supervisor] :: Supervisor m -> !UTCTime
[$sel:supervisorAsync:Supervisor] :: Supervisor m -> !(Async ())
[$sel:supervisorNotify:Supervisor] :: Supervisor m -> SupervisorMessage m -> m ()
[$sel:supervisorEnv:Supervisor] :: Supervisor m -> !(SupervisorEnv m)

-- | Internal record that represents an action being sent from threads
--   using the Capataz public API.
data ControlAction m
ForkWorker :: !(WorkerOptions m) -> !(WorkerId -> m ()) -> ControlAction m
[$sel:workerOptions:ForkWorker] :: ControlAction m -> !(WorkerOptions m)
[$sel:returnWorkerId:ForkWorker] :: ControlAction m -> !(WorkerId -> m ())
ForkSupervisor :: !(SupervisorOptions m) -> !(Supervisor m -> m ()) -> ControlAction m
[$sel:supervisorOptions:ForkWorker] :: ControlAction m -> !(SupervisorOptions m)
[$sel:returnSupervisor:ForkWorker] :: ControlAction m -> !(Supervisor m -> m ())
TerminateProcess :: !ProcessId -> !Text -> !(Bool -> m ()) -> ControlAction m
[$sel:processId:ForkWorker] :: ControlAction m -> !ProcessId
[$sel:processTerminationReason:ForkWorker] :: ControlAction m -> !Text
[$sel:notifyProcessTermination:ForkWorker] :: ControlAction m -> !(Bool -> m ())

-- | Internal exception thrown to the Capataz loop to indicate termination
--   of execution
data CapatazSignal
CapatazFailure :: CapatazSignal
RestartProcessException :: CapatazSignal
TerminateProcessException :: !ProcessId -> !Text -> CapatazSignal
[$sel:processId:CapatazFailure] :: CapatazSignal -> !ProcessId
[$sel:processTerminationReason:CapatazFailure] :: CapatazSignal -> !Text
BrutallyTerminateProcessException :: !ProcessId -> !Text -> CapatazSignal
[$sel:processId:CapatazFailure] :: CapatazSignal -> !ProcessId
[$sel:processTerminationReason:CapatazFailure] :: CapatazSignal -> !Text

-- | Internal exception triggered when a Worker violates error intensity
--   specification
data CapatazError
SupervisorIntensityReached :: !ProcessId -> !ProcessName -> !Int -> CapatazError
[$sel:processId:SupervisorIntensityReached] :: CapatazError -> !ProcessId
[$sel:processName:SupervisorIntensityReached] :: CapatazError -> !ProcessName
[$sel:processRestartCount:SupervisorIntensityReached] :: CapatazError -> !Int

-- | Internal record that indicates what type of callback function is being
--   invoked; this is used for telemetry purposes
data CallbackType
OnCompletion :: CallbackType
OnFailure :: CallbackType
OnTermination :: CallbackType
data ProcessType
SupervisorType :: ProcessType
WorkerType :: ProcessType

-- | Internal exception triggered when a callback of a Worker fails
data ProcessError
ProcessCallbackFailed :: !WorkerId -> !(Maybe SomeException) -> !SomeException -> !CallbackType -> ProcessError
[$sel:processId:ProcessCallbackFailed] :: ProcessError -> !WorkerId
[$sel:processError:ProcessCallbackFailed] :: ProcessError -> !(Maybe SomeException)
[$sel:processCallbackError:ProcessCallbackFailed] :: ProcessError -> !SomeException
[$sel:processCallbackType:ProcessCallbackFailed] :: ProcessError -> !CallbackType

-- | Internal event delivered from Worker threads to the Capataz thread to
--   indicate completion, failure or termination
data MonitorEvent
ProcessTerminated' :: !ProcessId -> !ProcessName -> !RestartCount -> !Text -> !UTCTime -> MonitorEvent
[$sel:processId:ProcessTerminated'] :: MonitorEvent -> !ProcessId
[$sel:processName:ProcessTerminated'] :: MonitorEvent -> !ProcessName
[$sel:processRestartCount:ProcessTerminated'] :: MonitorEvent -> !RestartCount
[$sel:processTerminationReason:ProcessTerminated'] :: MonitorEvent -> !Text
[$sel:monitorEventTime:ProcessTerminated'] :: MonitorEvent -> !UTCTime
ProcessFailed' :: !WorkerId -> !WorkerName -> !RestartCount -> !SomeException -> !UTCTime -> MonitorEvent
[$sel:processId:ProcessTerminated'] :: MonitorEvent -> !WorkerId
[$sel:processName:ProcessTerminated'] :: MonitorEvent -> !WorkerName
[$sel:processRestartCount:ProcessTerminated'] :: MonitorEvent -> !RestartCount
[$sel:processError:ProcessTerminated'] :: MonitorEvent -> !SomeException
[$sel:monitorEventTime:ProcessTerminated'] :: MonitorEvent -> !UTCTime
ProcessCompleted' :: !ProcessId -> !ProcessName -> !UTCTime -> MonitorEvent
[$sel:processId:ProcessTerminated'] :: MonitorEvent -> !ProcessId
[$sel:processName:ProcessTerminated'] :: MonitorEvent -> !ProcessName
[$sel:monitorEventTime:ProcessTerminated'] :: MonitorEvent -> !UTCTime
ProcessForcedRestart :: !ProcessId -> !ProcessName -> !UTCTime -> MonitorEvent
[$sel:processId:ProcessTerminated'] :: MonitorEvent -> !ProcessId
[$sel:processName:ProcessTerminated'] :: MonitorEvent -> !ProcessName
[$sel:monitorEventTime:ProcessTerminated'] :: MonitorEvent -> !UTCTime

-- | Internal record used as a state machine, indicating the state of a
--   supervisor process
data SupervisorStatus

-- | This state is set when the process is created and it starts spawning
--   its static process list.
Initializing :: SupervisorStatus

-- | This state is set when the supervisor process starts listenting to
--   both <a>ControlAction</a> and <a>MonitorEvent</a> messages.
Running :: SupervisorStatus

-- | This state is set when the supervisor process is terminating it's
--   assigned worker
Halting :: SupervisorStatus

-- | This state is set when the supervisor process is finished
Halted :: SupervisorStatus

-- | Internal message delivered to a supervisor process that can either be
--   a call from public API or an event from its monitored worker process.
data SupervisorMessage m

-- | Represents a request from done to the supervisor thread from another
--   thread using the public API
ControlAction :: !(ControlAction m) -> SupervisorMessage m

-- | Represents an event (failure, completion, etc) from a monitored worker
--   process to the supervisor
MonitorEvent :: !MonitorEvent -> SupervisorMessage m

-- | Internal Type to manage both <a>Worker</a> and <a>Supervisor</a>
--   processes
data Process m
WorkerProcess :: !(Worker m) -> Process m
SupervisorProcess :: !(Supervisor m) -> Process m

-- | Record used to specify how to <b>build</b> a runtime <a>Process</a> in
--   a static supervision tree; to create values of this type, you must
--   use:
--   
--   <ul>
--   <li><a>workerSpec</a> or <a>workerSpecWithDefaults</a> to build a
--   worker process</li>
--   <li><a>supervisorSpec</a> or <a>supervisorSpecWithDefaults</a> to
--   build a supervisor process</li>
--   </ul>
data ProcessSpec m
WorkerSpec :: (WorkerOptions m) -> ProcessSpec m
SupervisorSpec :: (SupervisorOptions m) -> ProcessSpec m

-- | 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.
data Capataz m
Capataz :: !(Supervisor m) -> !Teardown -> Capataz m
[$sel:capatazSupervisor:Capataz] :: Capataz m -> !(Supervisor m)
[$sel:capatazTeardown:Capataz] :: Capataz m -> !Teardown

-- | Internal utility record used to hold part of the runtime information
--   of a supervisor that acts as a parent of another supervisor.
data ParentSupervisorEnv m
ParentSupervisorEnv :: !SupervisorId -> !SupervisorName -> !(SupervisorMessage m -> m ()) -> !(CapatazEvent -> m ()) -> ParentSupervisorEnv m
[$sel:supervisorId:ParentSupervisorEnv] :: ParentSupervisorEnv m -> !SupervisorId
[$sel:supervisorName:ParentSupervisorEnv] :: ParentSupervisorEnv m -> !SupervisorName
[$sel:supervisorNotify:ParentSupervisorEnv] :: ParentSupervisorEnv m -> !(SupervisorMessage m -> m ())
[$sel:notifyEvent:ParentSupervisorEnv] :: ParentSupervisorEnv m -> !(CapatazEvent -> m ())

-- | Convenience internal utility record that contains all values related
--   to a supervisor process.
data SupervisorEnv m
SupervisorEnv :: !SupervisorId -> !SupervisorName -> !(SupervisorMessage m -> m ()) -> !(STM (SupervisorMessage m)) -> !(IORef (ProcessMap m)) -> !(TVar SupervisorStatus) -> !(SupervisorOptions m) -> !Int -> !NominalDiffTime -> !SupervisorRestartStrategy -> !ProcessTerminationOrder -> !(m ()) -> !(SomeException -> m ()) -> !(CapatazEvent -> m ()) -> SupervisorEnv m
[$sel:supervisorId:SupervisorEnv] :: SupervisorEnv m -> !SupervisorId
[$sel:supervisorName:SupervisorEnv] :: SupervisorEnv m -> !SupervisorName
[$sel:supervisorNotify:SupervisorEnv] :: SupervisorEnv m -> !(SupervisorMessage m -> m ())
[$sel:supervisorGetNotification:SupervisorEnv] :: SupervisorEnv m -> !(STM (SupervisorMessage m))
[$sel:supervisorProcessMap:SupervisorEnv] :: SupervisorEnv m -> !(IORef (ProcessMap m))
[$sel:supervisorStatusVar:SupervisorEnv] :: SupervisorEnv m -> !(TVar SupervisorStatus)
[$sel:supervisorOptions:SupervisorEnv] :: SupervisorEnv m -> !(SupervisorOptions m)

-- | 
--   <a>http://erlang.org/doc/design_principles/sup_princ.html#max_intensity</a>
[$sel:supervisorIntensity:SupervisorEnv] :: SupervisorEnv m -> !Int
[$sel:supervisorPeriodSeconds:SupervisorEnv] :: SupervisorEnv m -> !NominalDiffTime
[$sel:supervisorRestartStrategy:SupervisorEnv] :: SupervisorEnv m -> !SupervisorRestartStrategy
[$sel:supervisorProcessTerminationOrder:SupervisorEnv] :: SupervisorEnv m -> !ProcessTerminationOrder
[$sel:supervisorOnIntensityReached:SupervisorEnv] :: SupervisorEnv m -> !(m ())
[$sel:supervisorOnIntensityReached:SupervisorEnv] :: SupervisorEnv m -> !(SomeException -> m ())
[$sel:notifyEvent:SupervisorEnv] :: SupervisorEnv m -> !(CapatazEvent -> m ())

-- | Builds a <a>CapatazOptions</a> record with defaults on how to create a
--   capataz root supervisor, these defaults are:
--   
--   <ul>
--   <li>Intensity error tolerance is set to 1 error every 5 seconds</li>
--   <li>A <a>SupervisorRestartStrategy</a> of <a>OneForOne</a></li>
--   <li>A <a>ProcessTerminationOrder</a> of <a>OldestFirst</a></li>
--   </ul>
--   
--   This function is intended to be used in combination with
--   <tt>forkCapataz</tt>.
defCapatazOptions :: Monad m => Text -> (CapatazOptions m -> CapatazOptions m) -> CapatazOptions m

-- | Builds a <a>ProcessSpec</a> record for a supervisor process with
--   defaults from <a>supervisorSpecWithDefaults</a>. This function allows
--   overrides of these defaults using lenses.
--   
--   This function is used when building a supervisor branch in a static
--   supervision trees.
supervisorSpec :: Monad m => SupervisorName -> (SupervisorOptions m -> SupervisorOptions m) -> ProcessSpec m

-- | Builds a <a>ProcessSpec</a> record for a supervisor process with
--   defaults from <a>buildSupervisorOptionsWithDefaults</a>.
--   
--   This function is used when building a supervisor branch in a static
--   supervision trees.
supervisorSpecWithDefaults :: Monad m => SupervisorName -> ProcessSpec m

-- | Builds a <a>ProcessSpec</a> record for a worker process with defaults
--   from <a>workerSpecWithDefaults</a>. This function allows overrides of
--   these defaults using lenses.
--   
--   This function is used when building a worker in a static supervision
--   tree.
workerSpec :: Monad m => WorkerName -> m () -> (WorkerOptions m -> WorkerOptions m) -> ProcessSpec m

-- | Builds a <a>ProcessSpec</a> record for a worker process with defaults
--   from <a>workerSpecWithDefaults</a>. 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 <a>WorkerId</a> as a
--   parameter
workerSpec1 :: Monad m => WorkerName -> (WorkerId -> m ()) -> (WorkerOptions m -> WorkerOptions m) -> ProcessSpec m

-- | Builds a <a>ProcessSpec</a> record for a worker process with defaults
--   from <a>buildSupervisorOptionsWithDefaults</a>.
--   
--   This function is used when building a worker in a static supervision
--   tree.
workerSpecWithDefaults :: Monad m => WorkerName -> m () -> ProcessSpec m

-- | Builds a <a>SupervisorOptions</a> record with defaults from
--   <a>buildSupervisorOptionsWithDefaults</a>. This function allows
--   overrides of these defaults using lenses.
--   
--   This function is intended to be used in combination with
--   <tt>forkSupervisor</tt>.
buildSupervisorOptions :: Monad m => SupervisorName -> (SupervisorOptions m -> SupervisorOptions m) -> SupervisorOptions m

-- | Builds a <a>SupervisorOptions</a> record with defaults to create a
--   supervisor process, these defaults are:
--   
--   <ul>
--   <li>Intensity error tolerance is set to 1 error every 5 seconds</li>
--   <li>A <a>SupervisorRestartStrategy</a> of <a>OneForOne</a></li>
--   <li>A <a>ProcessTerminationOrder</a> of <a>OldestFirst</a></li>
--   </ul>
--   
--   This function is intended to be used in combination with
--   <tt>forkSupervisor</tt>.
buildSupervisorOptionsWithDefaults :: Monad m => SupervisorName -> SupervisorOptions m

-- | Builds a <a>WorkerOptions</a> record, keeps the defaults from
--   <a>buildWorkerOptionsWithDefaults</a> but allows overrides using
--   lenses.
--   
--   This function is intended to be used in combination with
--   <tt>forkWorker</tt>. See the capataz-simple-example project in the
--   examples directory for a demonstration.
buildWorkerOptions :: Monad m => WorkerName -> m () -> (WorkerOptions m -> WorkerOptions m) -> WorkerOptions m

-- | Builds a <a>WorkerOptions</a> record, keeps the defaults from
--   <a>buildWorkerOptionsWithDefaults</a> but allows overrides using
--   lenses.
--   
--   This function is intended to be used in combination with
--   <tt>forkWorker</tt>. See the capataz-simple-example project in the
--   examples directory for a demonstration.
--   
--   The given sub-routine will receive the <a>WorkerId</a> as a parameter.
buildWorkerOptions1 :: Monad m => WorkerName -> (WorkerId -> m ()) -> (WorkerOptions m -> WorkerOptions m) -> WorkerOptions m

-- | Builds a <a>WorkerOptions</a> record with defaults to create a worker
--   process, the defaults are:
--   
--   <ul>
--   <li>A <a>Transient</a> <a>WorkerRestartStrategy</a></li>
--   <li>A <a>WorkerTerminationPolicy</a> of a 3 seconds timeout</li>
--   <li>A _completion_ callback that just returns unit</li>
--   <li>A _termination_ callback that just returns unit</li>
--   <li>A _failure_ callback that just returns unit</li>
--   </ul>
--   
--   This function is intended to be used in combination with
--   <tt>forkWorker</tt>, for creating a worker in an static supervision
--   tree, use <a>workerSpecWithDefaults</a> instead. See the
--   capataz-simple-example project in the examples directory for a
--   demonstration.
buildWorkerOptionsWithDefaults :: Monad m => WorkerName -> m () -> WorkerOptions m

-- | Used for debugging purposes
getMaskingState :: MonadIO m => m MaskingState

-- | 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
unsafeTry :: (Exception e, MonadUnliftIO m) => m a -> m (Either e a)

-- | 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
fromAnyException :: Exception e => SomeException -> Maybe e
instance GHC.Generics.Generic (Control.Concurrent.Capataz.Internal.Types.ControlAction m)
instance GHC.Generics.Generic (Control.Concurrent.Capataz.Internal.Types.SupervisorMessage m)
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.CapatazEvent
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.CapatazEvent
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.SupervisorStatus
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.SupervisorStatus
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.SupervisorStatus
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.MonitorEvent
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.ProcessError
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.ProcessError
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.ProcessType
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.ProcessType
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.CallbackType
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.CallbackType
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.CallbackType
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.CapatazError
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.CapatazError
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.CapatazSignal
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.CapatazSignal
instance GHC.Generics.Generic (Control.Concurrent.Capataz.Internal.Types.WorkerOptions m)
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.WorkerRestartStrategy
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.WorkerRestartStrategy
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.WorkerRestartStrategy
instance GHC.Classes.Ord Control.Concurrent.Capataz.Internal.Types.SupervisorRestartStrategy
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.SupervisorRestartStrategy
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.SupervisorRestartStrategy
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.SupervisorRestartStrategy
instance GHC.Classes.Ord Control.Concurrent.Capataz.Internal.Types.ProcessTerminationOrder
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.ProcessTerminationOrder
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.ProcessTerminationOrder
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.ProcessTerminationOrder
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.ProcessRestartAction
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.ProcessRestartAction
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.ProcessRestartAction
instance GHC.Classes.Ord Control.Concurrent.Capataz.Internal.Types.WorkerTerminationPolicy
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.WorkerTerminationPolicy
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.WorkerTerminationPolicy
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.WorkerTerminationPolicy
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.ProcessThreadId
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.ProcessThreadId
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.ProcessThreadId
instance Control.Teardown.Internal.Types.HasTeardown (Control.Concurrent.Capataz.Internal.Types.Capataz m)
instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Concurrent.Capataz.Internal.Types.CapatazEvent
instance RIO.Prelude.Display.Display Control.Concurrent.Capataz.Internal.Types.CapatazEvent
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.SupervisorStatus
instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Concurrent.Capataz.Internal.Types.SupervisorStatus
instance GHC.Exception.Exception Control.Concurrent.Capataz.Internal.Types.ProcessError
instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Concurrent.Capataz.Internal.Types.ProcessType
instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Concurrent.Capataz.Internal.Types.CallbackType
instance GHC.Exception.Exception Control.Concurrent.Capataz.Internal.Types.CapatazError
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.CapatazError
instance GHC.Exception.Exception Control.Concurrent.Capataz.Internal.Types.CapatazSignal
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.CapatazSignal
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.WorkerRestartStrategy
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.SupervisorRestartStrategy
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.ProcessTerminationOrder
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.ProcessRestartAction
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.WorkerTerminationPolicy
instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Concurrent.Capataz.Internal.Types.ProcessThreadId

module Control.Concurrent.Capataz.Event

-- | Event delivered to the <a>$sel:notifyEvent:ParentSupervisorEnv</a>
--   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.
data CapatazEvent
InvalidSupervisorStatusReached :: !SupervisorId -> !SupervisorName -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
SupervisorStatusChanged :: !SupervisorId -> !SupervisorName -> !SupervisorStatus -> !SupervisorStatus -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:prevSupervisorStatus:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorStatus
[$sel:newSupervisorStatus:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorStatus
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessTerminated :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !Text -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:terminationReason:InvalidSupervisorStatusReached] :: CapatazEvent -> !Text
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessStarted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessRestarted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !Int -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:processRestartCount:InvalidSupervisorStatusReached] :: CapatazEvent -> !Int
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessCompleted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessFailed :: !SupervisorName -> !SupervisorId -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !SomeException -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:processError:InvalidSupervisorStatusReached] :: CapatazEvent -> !SomeException
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessCallbackExecuted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !(Maybe SomeException) -> !CallbackType -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:processCallbackError:InvalidSupervisorStatusReached] :: CapatazEvent -> !(Maybe SomeException)
[$sel:processCallbackType:InvalidSupervisorStatusReached] :: CapatazEvent -> !CallbackType
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessTerminationStarted :: !SupervisorName -> !SupervisorId -> !Text -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:terminationReason:InvalidSupervisorStatusReached] :: CapatazEvent -> !Text
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessTerminationFinished :: !SupervisorName -> !SupervisorId -> !Text -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:terminationReason:InvalidSupervisorStatusReached] :: CapatazEvent -> !Text
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
CapatazFailed :: !SupervisorId -> !SupervisorName -> !SomeException -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorError:InvalidSupervisorStatusReached] :: CapatazEvent -> !SomeException
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
CapatazTerminated :: !SupervisorName -> !SupervisorId -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime

module Control.Concurrent.Capataz.Internal.Types.Lens
class HasSupervisorIntensity s

-- | Specifies how many errors is a supervisor able to handle; check:
--   <a>http://erlang.org/doc/design_principles/sup_princ.html#max_intensity</a>.
supervisorIntensityL :: (HasSupervisorIntensity s, Functor f) => (Int -> f Int) -> s -> f s
class HasSupervisorPeriodSeconds s

-- | Specifies period of time in which a supervisor can receive a number of
--   errors specified in "supervisorIntensityL".
supervisorPeriodSecondsL :: (HasSupervisorPeriodSeconds s, Functor f) => (NominalDiffTime -> f NominalDiffTime) -> s -> f s
class HasSupervisorRestartStrategy s

-- | Specifies the <a>SupervisorRestartStrategy</a> for a root supervisor.
supervisorRestartStrategyL :: (HasSupervisorRestartStrategy s, Functor f) => (SupervisorRestartStrategy -> f SupervisorRestartStrategy) -> s -> f s
class HasSupervisorProcessSpecList s

-- | Specifies a static list of processes that start automatically with a
--   supervisor.
supervisorProcessSpecListL :: (HasSupervisorProcessSpecList s, Functor f) => ([ProcessSpec m] -> f [ProcessSpec m]) -> s m -> f (s m)
class HasSupervisorProcessTerminationOrder s

-- | Specifies order in which a supervisor is going to terminate its
--   supervised processes.
supervisorProcessTerminationOrderL :: (HasSupervisorProcessTerminationOrder s, Functor f) => (ProcessTerminationOrder -> f ProcessTerminationOrder) -> s -> f s
class HasSupervisorIntensityReachedCallback s

-- | Specifies a callback sub-routine that gets executed when there is a
--   breach in a supervisor's error intensity.
supervisorOnIntensityReachedL :: (HasSupervisorIntensityReachedCallback s, Functor f) => (m () -> f (m ())) -> s m -> f (s m)
class HasSupervisorFailureCallback s

-- | Specifies callback sub-routine that gets executed when a supervisor
--   fails.
supervisorOnFailureL :: (HasSupervisorFailureCallback s, Functor f) => ((SomeException -> m ()) -> f (SomeException -> m ())) -> s m -> f (s m)
onSystemEventL :: Functor f => ((CapatazEvent -> m ()) -> f (CapatazEvent -> m ())) -> CapatazOptions m -> f (CapatazOptions m)

-- | Specifies callback that gets executed when worker sub-routine has
--   runtime error.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnFailureL :: (Functor f) => ((SomeException -> m ()) -> f (SomeException -> m ())) -> WorkerOptions m -> f (WorkerOptions m)

-- | Specifies callback that gets executed when worker sub-routine
--   completes with no errors.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnCompletionL :: (Functor f) => (m () -> f (m ())) -> WorkerOptions m -> f (WorkerOptions m)

-- | Specifies callback that gets executed when worker sub-routine is
--   terminated by its supervisor; this may happen in case of a capataz
--   system shutdown or when there is an <a>AllForOne</a> restart policy in
--   place.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnTerminationL :: Functor f => (m () -> f (m ())) -> WorkerOptions m -> f (WorkerOptions m)

-- | Specifies how to handle a worker termination. See
--   <a>WorkerTerminationPolicy</a> documentation for more details.
workerTerminationPolicyL :: Functor f => (WorkerTerminationPolicy -> f WorkerTerminationPolicy) -> WorkerOptions m -> f (WorkerOptions m)

-- | Specifies how supervisor should deal with an error when worker fails
--   or completes. See <a>WorkerRestartStrategy</a> documentation for more
--   details.
workerRestartStrategyL :: Functor f => (WorkerRestartStrategy -> f WorkerRestartStrategy) -> WorkerOptions m -> f (WorkerOptions m)
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorFailureCallback Control.Concurrent.Capataz.Internal.Types.SupervisorOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorFailureCallback Control.Concurrent.Capataz.Internal.Types.CapatazOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorIntensityReachedCallback Control.Concurrent.Capataz.Internal.Types.SupervisorOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorIntensityReachedCallback Control.Concurrent.Capataz.Internal.Types.CapatazOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorProcessTerminationOrder (Control.Concurrent.Capataz.Internal.Types.SupervisorOptions m)
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorProcessTerminationOrder (Control.Concurrent.Capataz.Internal.Types.CapatazOptions m)
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorProcessSpecList Control.Concurrent.Capataz.Internal.Types.SupervisorOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorProcessSpecList Control.Concurrent.Capataz.Internal.Types.CapatazOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorRestartStrategy (Control.Concurrent.Capataz.Internal.Types.SupervisorOptions m)
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorRestartStrategy (Control.Concurrent.Capataz.Internal.Types.CapatazOptions m)
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorPeriodSeconds (Control.Concurrent.Capataz.Internal.Types.SupervisorOptions m)
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorPeriodSeconds (Control.Concurrent.Capataz.Internal.Types.CapatazOptions m)
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorIntensity (Control.Concurrent.Capataz.Internal.Types.SupervisorOptions m)
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorIntensity (Control.Concurrent.Capataz.Internal.Types.CapatazOptions m)


-- | This module contains:
--   
--   <ul>
--   <li>Functions to manipulate the state of the Supervisor record</li>
--   <li>Utility functions used for communication between threads</li>
--   <li>Public API utility functions</li>
--   </ul>
module Control.Concurrent.Capataz.Internal.Util

-- | Returns only the number of the ThreadId.
getTidNumber :: ThreadId -> Maybe Text

-- | Internal functions that overwrites the GHC thread name, for increasing
--   traceability on GHC internals.
setProcessThreadName :: MonadIO m => WorkerId -> WorkerName -> m ()

-- | Gets the <a>ProcessId</a> of both a Worker or Supervisor process.
getProcessId :: Process m -> ProcessId

-- | Gets a supervised <a>Process</a> from a <a>Supervisor</a> instance.
fetchProcess :: MonadIO m => SupervisorEnv m -> ProcessId -> m (Maybe (Process m))

-- | Appends a new <a>Process</a> to the <a>Supervisor</a> existing process
--   map.
appendProcessToMap :: MonadIO m => SupervisorEnv m -> Process m -> m ()

-- | Removes a <a>Process</a> from a <a>Supervisor</a> existing process
--   map.
removeProcessFromMap :: MonadIO m => SupervisorEnv m -> ProcessId -> m ()

-- | Function to modify a <a>Supervisor</a> process map using a pure
--   function.
resetProcessMap :: MonadIO m => SupervisorEnv m -> (ProcessMap m -> ProcessMap m) -> m ()

-- | Function to get a snapshot of a <a>Supervisor</a> process map.
readProcessMap :: MonadIO m => SupervisorEnv m -> m (ProcessMap m)

-- | Returns all processes of a <a>Supervisor</a> by
--   <a>ProcessTerminationOrder</a>. This is used on <a>AllForOne</a>
--   restarts and shutdown operations.
sortProcessesByTerminationOrder :: ProcessTerminationOrder -> ProcessMap m -> [Process m]

-- | Returns the <a>SupervisorStatus</a>, this sub-routine will retry
--   transaction until its associated <a>Supervisor</a> has a status
--   different from <a>Initializing</a>.
readSupervisorStatusSTM :: TVar SupervisorStatus -> STM SupervisorStatus

-- | Executes transaction that returns the <a>SupervisorStatus</a>.
readSupervisorStatus :: MonadIO m => SupervisorEnv m -> m SupervisorStatus

-- | Modifes the <a>Supervisor</a> status.
--   
--   <b>IMPORTANT</b> This is the only function that should be used for
--   this purpose given it has the side-effect of notifying a status change
--   via the <a>$sel:notifyEvent:ParentSupervisorEnv</a> sub-routine,
--   orginally given in the <tt>CapatazOption</tt> record.
writeSupervisorStatus :: MonadIO m => SupervisorEnv m -> SupervisorStatus -> m ()

-- | Used from public API functions to send <a>ControlAction</a> messages
--   to a Supervisor thread loop.
sendControlMsg :: SupervisorEnv m -> ControlAction m -> m ()

-- | Used from public API functions to send ControlAction messages to the a
--   Supervisor thread loop, it receives an IO sub-routine that expects an
--   IO operation that blocks a thread until the message is done.
sendSyncControlMsg :: MonadIO m => SupervisorEnv m -> (m () -> ControlAction m) -> m ()

-- | Utility function to transform a <a>CapatazOptions</a> record to a
--   <a>SupervisorOptions</a> record.
capatazOptionsToSupervisorOptions :: CapatazOptions m -> SupervisorOptions m

-- | Utility function to transform a <a>SupervisorEnv</a> record to a
--   <a>ParentSupervisorEnv</a> record; used on functions where supervision
--   of supervisors is managed.
toParentSupervisorEnv :: SupervisorEnv m -> ParentSupervisorEnv m


-- | This module contains all logic related to error handling when spawning
--   threads to execute Worker sub-routines
module Control.Concurrent.Capataz.Internal.Worker

-- | Decorates the given <tt>IO ()</tt> sub-routine with failure handling
workerMain :: (MonadUnliftIO m) => ParentSupervisorEnv m -> WorkerOptions m -> WorkerId -> RestartCount -> m (Worker m)

-- | Internal function that forks a worker thread on the Capataz thread;
--   note this is different from the public <tt>forkWorker</tt> function
--   which sends a message to the capataz loop
forkWorker :: (MonadUnliftIO m) => ParentSupervisorEnv m -> WorkerOptions m -> Maybe (WorkerId, RestartCount) -> m (Worker m)

module Control.Concurrent.Capataz.Internal.Supervisor

-- | Internal function that forks a supervisor thread; note this is
--   different from the public <tt>forkSupervisor</tt> function which sends
--   a message to the supervisor loop.
forkSupervisor :: (MonadUnliftIO m) => ParentSupervisorEnv m -> SupervisorOptions m -> Maybe (ProcessId, RestartCount) -> m (Supervisor m)

-- | Utility function that builds an utility record which is used on all
--   internal APIs of the supervision logic.
buildSupervisorEnv :: MonadIO m => (CapatazEvent -> m ()) -> (SupervisorMessage m -> m ()) -> STM (SupervisorMessage m) -> SupervisorId -> SupervisorOptions m -> m (SupervisorEnv m)

-- | Handles an event produced by one of the processes this supervisor
--   monitors.
handleMonitorEvent :: (MonadUnliftIO m) => SupervisorEnv m -> MonitorEvent -> m Bool

-- | Handles an action triggered by the public Capataz API.
handleControlAction :: (MonadUnliftIO m) => SupervisorEnv m -> ControlAction m -> m Bool

-- | Executes the shutdown operation of a Supervisor, including the
--   termination of its supervised processes.
haltSupervisor :: (MonadUnliftIO m) => Text -> SupervisorEnv m -> m ()

-- | Handles all messages that a Supervisor can receive from its monitored
--   processes or from the public API.
handleSupervisorMessage :: (MonadUnliftIO m) => SupervisorEnv m -> SupervisorMessage m -> m Bool

-- | This sub-routine executes the main thread loop of a <a>Supervisor</a>
--   instance.
supervisorLoop :: (MonadUnliftIO m) => (forall b. m b -> m b) -> ParentSupervisorEnv m -> SupervisorEnv m -> RestartCount -> m ()

-- | This sub-routine starts a Supervisor thread and initializes its
--   processList.
supervisorMain :: (MonadUnliftIO m) => ParentSupervisorEnv m -> SupervisorOptions m -> SupervisorId -> RestartCount -> m (Supervisor m)

-- | Tracks difference between two timestamps so that we keep track of a
--   Supervisor error intensity.
calcDiffSeconds :: MonadIO m => UTCTime -> m NominalDiffTime

-- | Checks restart counts and worker start times to assess if the
--   Supervisor error intensity has been breached, see
--   <a>ProcessRestartAction</a> for possible outcomes.
calcRestartAction :: SupervisorEnv m -> Int -> NominalDiffTime -> ProcessRestartAction

-- | Sub-routine responsible of executing a
--   <a>SupervisorRestartStrategy</a>.
execCapatazRestartStrategy :: (MonadUnliftIO m) => SupervisorEnv m -> ProcessId -> ProcessSpec m -> Int -> m ()

-- | Executes a restart action returned from the invokation of
--   "calcRestartAction".
execRestartAction :: (MonadUnliftIO m) => SupervisorEnv m -> ProcessId -> ProcessSpec m -> Text -> UTCTime -> Int -> m ()

-- | Restarts _all_ processes that are supervised by Supervisor, invoked
--   when one worker green thread fails and causes sibling process threads
--   to get restarted as well (e.g. <a>AllForOne</a> supervisor restart
--   strategy).
restartProcessList :: (MonadUnliftIO m) => SupervisorEnv m -> WorkerId -> RestartCount -> m [Process m]

-- | Sub-routine that is used when there is a restart request sent to a
--   Process caused by an <a>AllForOne</a> restart from a failing sibling
--   process.
forceRestartProcess :: MonadIO m => SupervisorEnv m -> Process m -> m ()

-- | Starts a new worker thread taking into account an existing
--   <a>WorkerId</a> and keeping a <a>RestartCount</a> to manage the
--   Supervisor error intensity.
restartWorker :: (MonadUnliftIO m) => SupervisorEnv m -> WorkerOptions m -> WorkerId -> RestartCount -> m (Process m)

-- | Starts a new Supervisor thread taking into account an existing
--   <a>SupervisorId</a> and keeping a <a>RestartCount</a> to manage the
--   parent Supervisor error intensity.
restartSupervisor :: (MonadUnliftIO m) => ParentSupervisorEnv m -> SupervisorOptions m -> ProcessId -> RestartCount -> m (Process m)

-- | Executes restart strategy for when a worker finishes it execution
--   because of a completion (e.g. worker sub-routine finished without any
--   errors).
handleWorkerCompleted :: (MonadUnliftIO m) => SupervisorEnv m -> Worker m -> m ()

-- | Executes restart strategy for when a process finishes it execution
--   because of a completion (e.g. worker sub-routine finished without any
--   errors).
handleProcessCompleted :: (MonadUnliftIO m) => SupervisorEnv m -> ProcessId -> UTCTime -> m ()

-- | Executes restart strategy for when a worker finishes it execution
--   because of a failure.
handleWorkerFailed :: (MonadUnliftIO m) => SupervisorEnv m -> Worker m -> Int -> m ()

-- | Executes restart strategy for when a supervisor finishes it execution
--   because of a failure.
handleSupervisorFailed :: (MonadUnliftIO m) => SupervisorEnv m -> Supervisor m -> Int -> m ()

-- | Executes restart strategy for when a process finishes it execution
--   because of a failure.
handleProcessFailed :: (MonadUnliftIO m) => SupervisorEnv m -> WorkerId -> SomeException -> Int -> m ()

-- | Executes restart strategy for when a worker finishes it execution
--   because of a termination from its supervisor.
handleWorkerTerminated :: (MonadUnliftIO m) => SupervisorEnv m -> Worker m -> Int -> m ()

-- | Executes restart strategy for when a supervisor finishes it execution
--   because of a termination from its parent supervisor.
handleSupervisorTerminated :: (MonadUnliftIO m) => SupervisorEnv m -> Supervisor m -> Int -> m ()

-- | Executes restart strategy for when a process finishes it execution
--   because of a termination from its supervisor.
handleProcessTerminated :: (MonadUnliftIO m) => SupervisorEnv m -> ProcessId -> Text -> Int -> m ()


-- | This module contains:
--   
--   <ul>
--   <li>Functions exported on the public API</li>
--   <li>High level message handlers of the supervisor thread loop</li>
--   </ul>
module Control.Concurrent.Capataz.Internal.Core

-- | Utility typeclass to call public supervision API with types that
--   contain a supervisor (e.g. Capataz record).
class HasSupervisor a

-- | Fetches a supervisor from a record internals.
getSupervisor :: HasSupervisor a => a m -> Supervisor m

-- | Creates a green thread from an <tt>IO ()</tt> sub-routine. Depending
--   in options defined in the <a>WorkerOptions</a> record, it will
--   automatically restart this sub-routine in case of failures.
--   
--   See documentation of related functions:
--   
--   <ul>
--   <li><a>buildWorkerOptionsWithDefaults</a></li>
--   <li><a>buildWorkerOptions</a></li>
--   </ul>
forkWorker :: (MonadIO m, HasSupervisor supervisor) => WorkerOptions m -> supervisor m -> m WorkerId

-- | Creates a green thread which monitors other green threads for failures
--   and restarts them using settings defined on <a>SupervisorOptions</a>.
--   
--   See documentation of related functions:
--   
--   <ul>
--   <li><tt>buildSupervisorOptionsWithDefault</tt></li>
--   <li><a>buildSupervisorOptions</a></li>
--   </ul>
forkSupervisor :: (MonadIO m, HasSupervisor parentSupervisor) => SupervisorOptions m -> parentSupervisor m -> m (Supervisor m)

-- | Creates a Capataz record, which holds both a root supervisor and a
--   <a>Teardown</a> to shut down the system. The root supervisor monitors
--   failures on process threads defined with
--   <a>$sel:supervisorProcessSpecList:CapatazOptions</a> or created
--   dynamically using <a>forkWorker</a> or <a>forkSupervisor</a>.
forkCapataz :: (MonadUnliftIO m, MonadIO m) => Text -> (CapatazOptions m -> CapatazOptions m) -> m (Capataz m)

-- | Stops the execution of a green thread being supervised by the given
--   supervisor.
--   
--   <b>IMPORTANT</b> If <a>ProcessId</a> maps to a worker that is
--   configured with a <a>Permanent</a> worker restart strategy, the worker
--   green thread __will be restarted again__.
terminateProcess :: (MonadIO m, HasSupervisor supervisor) => Text -> ProcessId -> supervisor m -> m Bool

-- | Terminates a <a>Capataz</a> system (all supervised threads) and
--   returns a <a>TeardownResult</a>
terminateCapataz :: MonadIO m => Capataz m -> m TeardownResult

-- | Terminates a <a>Capataz</a> system (all supervised threads)
terminateCapataz_ :: MonadIO m => Capataz m -> m ()

-- | Joins the thread of the root supervisor of the given capataz system to
--   the current thread.
joinCapatazThread :: MonadIO m => Capataz m -> m ()

-- | Gets the process identifier of a <a>Supervisor</a>; normally used for
--   termination.
getSupervisorProcessId :: Supervisor m -> ProcessId

-- | Gets the <a>Async</a> of a Supervisor thread.
--   
--   NOTE: There is no way to get the <a>Async</a> value of the root
--   supervisor; this is done on-purpose to avoid error scenarios.
getSupervisorAsync :: Supervisor m -> Async ()

-- | Gets <a>Teardown</a> record of this capataz system.
getCapatazTeardown :: Capataz m -> Teardown
instance Control.Concurrent.Capataz.Internal.Core.HasSupervisor Control.Concurrent.Capataz.Internal.Types.Capataz
instance Control.Concurrent.Capataz.Internal.Core.HasSupervisor Control.Concurrent.Capataz.Internal.Types.Supervisor

module Control.Concurrent.Capataz.Lens

-- | <a>&amp;</a> is a reverse application operator. This provides
--   notational convenience. Its precedence is one higher than that of the
--   forward application operator <a>$</a>, which allows <a>&amp;</a> to be
--   nested in <a>$</a>.
--   
--   <pre>
--   &gt;&gt;&gt; 5 &amp; (+1) &amp; show
--   "6"
--   </pre>
(&) :: () => a -> a -> b -> b
infixl 1 &

-- | (<a>^.</a>) applies a getter to a value; in other words, it gets a
--   value out of a structure using a getter (which can be a lens,
--   traversal, fold, etc.).
--   
--   Getting 1st field of a tuple:
--   
--   <pre>
--   (<a>^.</a> <a>_1</a>) :: (a, b) -&gt; a
--   (<a>^.</a> <a>_1</a>) = <a>fst</a>
--   </pre>
--   
--   When (<a>^.</a>) is used with a traversal, it combines all results
--   using the <a>Monoid</a> instance for the resulting type. For instance,
--   for lists it would be simple concatenation:
--   
--   <pre>
--   &gt;&gt;&gt; ("str","ing") ^. each
--   "string"
--   </pre>
--   
--   The reason for this is that traversals use <a>Applicative</a>, and the
--   <a>Applicative</a> instance for <a>Const</a> uses monoid concatenation
--   to combine “effects” of <a>Const</a>.
--   
--   A non-operator version of (<a>^.</a>) is called <tt>view</tt>, and
--   it's a bit more general than (<a>^.</a>) (it works in
--   <tt>MonadReader</tt>). If you need the general version, you can get it
--   from <a>microlens-mtl</a>; otherwise there's <a>view</a> available in
--   <a>Lens.Micro.Extras</a>.
(^.) :: () => s -> Getting a s a -> a
infixl 8 ^.

-- | <a>set</a> is a synonym for (<a>.~</a>).
--   
--   Setting the 1st component of a pair:
--   
--   <pre>
--   <a>set</a> <a>_1</a> :: x -&gt; (a, b) -&gt; (x, b)
--   <a>set</a> <a>_1</a> = \x t -&gt; (x, snd t)
--   </pre>
--   
--   Using it to rewrite (<a>&lt;$</a>):
--   
--   <pre>
--   <a>set</a> <a>mapped</a> :: <a>Functor</a> f =&gt; a -&gt; f b -&gt; f a
--   <a>set</a> <a>mapped</a> = (<a>&lt;$</a>)
--   </pre>
set :: () => ASetter s t a b -> b -> s -> t
view :: MonadReader s m => Getting a s a -> m a

-- | Specifies callback sub-routine that gets executed when a supervisor
--   fails.
supervisorOnFailureL :: (HasSupervisorFailureCallback s, Functor f) => ((SomeException -> m ()) -> f (SomeException -> m ())) -> s m -> f (s m)

-- | Specifies a callback sub-routine that gets executed when there is a
--   breach in a supervisor's error intensity.
supervisorOnIntensityReachedL :: (HasSupervisorIntensityReachedCallback s, Functor f) => (m () -> f (m ())) -> s m -> f (s m)

-- | Specifies order in which a supervisor is going to terminate its
--   supervised processes.
supervisorProcessTerminationOrderL :: (HasSupervisorProcessTerminationOrder s, Functor f) => (ProcessTerminationOrder -> f ProcessTerminationOrder) -> s -> f s

-- | Specifies a static list of processes that start automatically with a
--   supervisor.
supervisorProcessSpecListL :: (HasSupervisorProcessSpecList s, Functor f) => ([ProcessSpec m] -> f [ProcessSpec m]) -> s m -> f (s m)

-- | Specifies the <a>SupervisorRestartStrategy</a> for a root supervisor.
supervisorRestartStrategyL :: (HasSupervisorRestartStrategy s, Functor f) => (SupervisorRestartStrategy -> f SupervisorRestartStrategy) -> s -> f s

-- | Specifies period of time in which a supervisor can receive a number of
--   errors specified in "supervisorIntensityL".
supervisorPeriodSecondsL :: (HasSupervisorPeriodSeconds s, Functor f) => (NominalDiffTime -> f NominalDiffTime) -> s -> f s

-- | Specifies how many errors is a supervisor able to handle; check:
--   <a>http://erlang.org/doc/design_principles/sup_princ.html#max_intensity</a>.
supervisorIntensityL :: (HasSupervisorIntensity s, Functor f) => (Int -> f Int) -> s -> f s
onSystemEventL :: Functor f => ((CapatazEvent -> m ()) -> f (CapatazEvent -> m ())) -> CapatazOptions m -> f (CapatazOptions m)

-- | Specifies callback that gets executed when worker sub-routine has
--   runtime error.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnFailureL :: (Functor f) => ((SomeException -> m ()) -> f (SomeException -> m ())) -> WorkerOptions m -> f (WorkerOptions m)

-- | Specifies callback that gets executed when worker sub-routine
--   completes with no errors.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnCompletionL :: (Functor f) => (m () -> f (m ())) -> WorkerOptions m -> f (WorkerOptions m)

-- | Specifies callback that gets executed when worker sub-routine is
--   terminated by its supervisor; this may happen in case of a capataz
--   system shutdown or when there is an <a>AllForOne</a> restart policy in
--   place.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnTerminationL :: Functor f => (m () -> f (m ())) -> WorkerOptions m -> f (WorkerOptions m)

-- | Specifies how to handle a worker termination. See
--   <a>WorkerTerminationPolicy</a> documentation for more details.
workerTerminationPolicyL :: Functor f => (WorkerTerminationPolicy -> f WorkerTerminationPolicy) -> WorkerOptions m -> f (WorkerOptions m)

-- | Specifies how supervisor should deal with an error when worker fails
--   or completes. See <a>WorkerRestartStrategy</a> documentation for more
--   details.
workerRestartStrategyL :: Functor f => (WorkerRestartStrategy -> f WorkerRestartStrategy) -> WorkerOptions m -> f (WorkerOptions m)


-- | Public API for the capataz library
--   
--   Capataz is a library that brings an OTP-like supervisor API to the
--   Haskell concurrency toolset.
module Control.Concurrent.Capataz

-- | Utility typeclass to call public supervision API with types that
--   contain a supervisor (e.g. Capataz record).
class HasSupervisor a

-- | Fetches a supervisor from a record internals.
getSupervisor :: HasSupervisor a => a m -> Supervisor m

-- | Internal record that indicates what type of callback function is being
--   invoked; this is used for telemetry purposes
data CallbackType
OnCompletion :: CallbackType
OnFailure :: CallbackType
OnTermination :: CallbackType
type WorkerId = UUID
type WorkerName = Text

-- | Specifies how a Supervisor deals with the lifecycle of worker process
--   in case of completion without errors and failure.
data WorkerRestartStrategy

-- | Supervisor will <b>always</b> restart a worker process, in both
--   completion and failure scenarios.
Permanent :: WorkerRestartStrategy

-- | Supervisor will <b>only</b> restart worker process if it has a failure
--   in execution.
Transient :: WorkerRestartStrategy

-- | Supervisor will <b>never</b> restart a worker, even on failure.
Temporary :: WorkerRestartStrategy

-- | Defines how a <a>Worker</a> process termination should be handled by
--   its supervisor.
data WorkerTerminationPolicy

-- | Supervisor waits until infinity for the worker termination callback to
--   finish execution.
Infinity :: WorkerTerminationPolicy

-- | Supervisor terminates worker process without a chance to call its
--   termination callback.
BrutalTermination :: WorkerTerminationPolicy

-- | Supervisor allows a number of milliseconds for worker termination
--   callback complete, if not completed by specified milliseconds the
--   termination is cancelled via a <a>BrutalTermination</a> signal.
TimeoutMillis :: !Int -> WorkerTerminationPolicy

-- | Specifies all options that can be used to create a Worker Process. You
--   may create a record of this type via the smart constructor
--   <a>buildWorkerOptions</a>.
data WorkerOptions m
type ProcessId = UUID

-- | Record used to specify how to <b>build</b> a runtime <a>Process</a> in
--   a static supervision tree; to create values of this type, you must
--   use:
--   
--   <ul>
--   <li><a>workerSpec</a> or <a>workerSpecWithDefaults</a> to build a
--   worker process</li>
--   <li><a>supervisorSpec</a> or <a>supervisorSpecWithDefaults</a> to
--   build a supervisor process</li>
--   </ul>
data ProcessSpec m
WorkerSpec :: (WorkerOptions m) -> ProcessSpec m
SupervisorSpec :: (SupervisorOptions m) -> ProcessSpec m
data ProcessType
SupervisorType :: ProcessType
WorkerType :: ProcessType

-- | Specifies the order in which supervised process should be terminated
--   by a Supervisor in case of a restart or shutdown.
data ProcessTerminationOrder

-- | Supervisor terminates supervised process from most recent to oldest.
NewestFirst :: ProcessTerminationOrder

-- | Supervisor terminates supervised process from oldest to most recent.
OldestFirst :: ProcessTerminationOrder

-- | Internal exception triggered when a callback of a Worker fails
data ProcessError
ProcessCallbackFailed :: !WorkerId -> !(Maybe SomeException) -> !SomeException -> !CallbackType -> ProcessError
[$sel:processId:ProcessCallbackFailed] :: ProcessError -> !WorkerId
[$sel:processError:ProcessCallbackFailed] :: ProcessError -> !(Maybe SomeException)
[$sel:processCallbackError:ProcessCallbackFailed] :: ProcessError -> !SomeException
[$sel:processCallbackType:ProcessCallbackFailed] :: ProcessError -> !CallbackType
type SupervisorId = UUID
type SupervisorName = Text
data Supervisor m

-- | Specifies how a Supervisor restarts a failing process.
data SupervisorRestartStrategy

-- | 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.
AllForOne :: SupervisorRestartStrategy

-- | Supervisor only restarts the supervised process that failed.
OneForOne :: SupervisorRestartStrategy

-- | Internal record used as a state machine, indicating the state of a
--   supervisor process
data SupervisorStatus

-- | This state is set when the process is created and it starts spawning
--   its static process list.
Initializing :: SupervisorStatus

-- | This state is set when the supervisor process starts listenting to
--   both <a>ControlAction</a> and <a>MonitorEvent</a> messages.
Running :: SupervisorStatus

-- | This state is set when the supervisor process is terminating it's
--   assigned worker
Halting :: SupervisorStatus

-- | This state is set when the supervisor process is finished
Halted :: SupervisorStatus
data SupervisorOptions m

-- | Allows to:
--   
--   <ul>
--   <li>Specify options for the root <a>Supervisor</a> of a capataz
--   system.</li>
--   <li>Provide a <a>$sel:notifyEvent:ParentSupervisorEnv</a> callback to
--   monitor or log a capataz system.</li>
--   </ul>
data CapatazOptions m

-- | 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.
data Capataz m

-- | Builds a <a>SupervisorOptions</a> record with defaults from
--   <a>buildSupervisorOptionsWithDefaults</a>. This function allows
--   overrides of these defaults using lenses.
--   
--   This function is intended to be used in combination with
--   <tt>forkSupervisor</tt>.
buildSupervisorOptions :: Monad m => SupervisorName -> (SupervisorOptions m -> SupervisorOptions m) -> SupervisorOptions m

-- | Builds a <a>SupervisorOptions</a> record with defaults to create a
--   supervisor process, these defaults are:
--   
--   <ul>
--   <li>Intensity error tolerance is set to 1 error every 5 seconds</li>
--   <li>A <a>SupervisorRestartStrategy</a> of <a>OneForOne</a></li>
--   <li>A <a>ProcessTerminationOrder</a> of <a>OldestFirst</a></li>
--   </ul>
--   
--   This function is intended to be used in combination with
--   <tt>forkSupervisor</tt>.
buildSupervisorOptionsWithDefaults :: Monad m => SupervisorName -> SupervisorOptions m

-- | Builds a <a>WorkerOptions</a> record, keeps the defaults from
--   <a>buildWorkerOptionsWithDefaults</a> but allows overrides using
--   lenses.
--   
--   This function is intended to be used in combination with
--   <tt>forkWorker</tt>. See the capataz-simple-example project in the
--   examples directory for a demonstration.
buildWorkerOptions :: Monad m => WorkerName -> m () -> (WorkerOptions m -> WorkerOptions m) -> WorkerOptions m

-- | Builds a <a>WorkerOptions</a> record with defaults to create a worker
--   process, the defaults are:
--   
--   <ul>
--   <li>A <a>Transient</a> <a>WorkerRestartStrategy</a></li>
--   <li>A <a>WorkerTerminationPolicy</a> of a 3 seconds timeout</li>
--   <li>A _completion_ callback that just returns unit</li>
--   <li>A _termination_ callback that just returns unit</li>
--   <li>A _failure_ callback that just returns unit</li>
--   </ul>
--   
--   This function is intended to be used in combination with
--   <tt>forkWorker</tt>, for creating a worker in an static supervision
--   tree, use <a>workerSpecWithDefaults</a> instead. See the
--   capataz-simple-example project in the examples directory for a
--   demonstration.
buildWorkerOptionsWithDefaults :: Monad m => WorkerName -> m () -> WorkerOptions m

-- | Builds a <a>ProcessSpec</a> record for a supervisor process with
--   defaults from <a>supervisorSpecWithDefaults</a>. This function allows
--   overrides of these defaults using lenses.
--   
--   This function is used when building a supervisor branch in a static
--   supervision trees.
supervisorSpec :: Monad m => SupervisorName -> (SupervisorOptions m -> SupervisorOptions m) -> ProcessSpec m

-- | Builds a <a>ProcessSpec</a> record for a supervisor process with
--   defaults from <a>buildSupervisorOptionsWithDefaults</a>.
--   
--   This function is used when building a supervisor branch in a static
--   supervision trees.
supervisorSpecWithDefaults :: Monad m => SupervisorName -> ProcessSpec m

-- | Builds a <a>ProcessSpec</a> record for a worker process with defaults
--   from <a>workerSpecWithDefaults</a>. This function allows overrides of
--   these defaults using lenses.
--   
--   This function is used when building a worker in a static supervision
--   tree.
workerSpec :: Monad m => WorkerName -> m () -> (WorkerOptions m -> WorkerOptions m) -> ProcessSpec m

-- | Builds a <a>ProcessSpec</a> record for a worker process with defaults
--   from <a>buildSupervisorOptionsWithDefaults</a>.
--   
--   This function is used when building a worker in a static supervision
--   tree.
workerSpecWithDefaults :: Monad m => WorkerName -> m () -> ProcessSpec m
onSystemEventL :: Functor f => ((CapatazEvent -> m ()) -> f (CapatazEvent -> m ())) -> CapatazOptions m -> f (CapatazOptions m)

-- | Specifies how many errors is a supervisor able to handle; check:
--   <a>http://erlang.org/doc/design_principles/sup_princ.html#max_intensity</a>.
supervisorIntensityL :: (HasSupervisorIntensity s, Functor f) => (Int -> f Int) -> s -> f s

-- | Specifies period of time in which a supervisor can receive a number of
--   errors specified in "supervisorIntensityL".
supervisorPeriodSecondsL :: (HasSupervisorPeriodSeconds s, Functor f) => (NominalDiffTime -> f NominalDiffTime) -> s -> f s

-- | Specifies the <a>SupervisorRestartStrategy</a> for a root supervisor.
supervisorRestartStrategyL :: (HasSupervisorRestartStrategy s, Functor f) => (SupervisorRestartStrategy -> f SupervisorRestartStrategy) -> s -> f s

-- | Specifies a static list of processes that start automatically with a
--   supervisor.
supervisorProcessSpecListL :: (HasSupervisorProcessSpecList s, Functor f) => ([ProcessSpec m] -> f [ProcessSpec m]) -> s m -> f (s m)

-- | Specifies order in which a supervisor is going to terminate its
--   supervised processes.
supervisorProcessTerminationOrderL :: (HasSupervisorProcessTerminationOrder s, Functor f) => (ProcessTerminationOrder -> f ProcessTerminationOrder) -> s -> f s

-- | Specifies a callback sub-routine that gets executed when there is a
--   breach in a supervisor's error intensity.
supervisorOnIntensityReachedL :: (HasSupervisorIntensityReachedCallback s, Functor f) => (m () -> f (m ())) -> s m -> f (s m)

-- | Specifies callback sub-routine that gets executed when a supervisor
--   fails.
supervisorOnFailureL :: (HasSupervisorFailureCallback s, Functor f) => ((SomeException -> m ()) -> f (SomeException -> m ())) -> s m -> f (s m)

-- | Specifies callback that gets executed when worker sub-routine has
--   runtime error.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnFailureL :: (Functor f) => ((SomeException -> m ()) -> f (SomeException -> m ())) -> WorkerOptions m -> f (WorkerOptions m)

-- | Specifies callback that gets executed when worker sub-routine
--   completes with no errors.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnCompletionL :: (Functor f) => (m () -> f (m ())) -> WorkerOptions m -> f (WorkerOptions m)

-- | Specifies callback that gets executed when worker sub-routine is
--   terminated by its supervisor; this may happen in case of a capataz
--   system shutdown or when there is an <a>AllForOne</a> restart policy in
--   place.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnTerminationL :: Functor f => (m () -> f (m ())) -> WorkerOptions m -> f (WorkerOptions m)

-- | Specifies how to handle a worker termination. See
--   <a>WorkerTerminationPolicy</a> documentation for more details.
workerTerminationPolicyL :: Functor f => (WorkerTerminationPolicy -> f WorkerTerminationPolicy) -> WorkerOptions m -> f (WorkerOptions m)

-- | Specifies how supervisor should deal with an error when worker fails
--   or completes. See <a>WorkerRestartStrategy</a> documentation for more
--   details.
workerRestartStrategyL :: Functor f => (WorkerRestartStrategy -> f WorkerRestartStrategy) -> WorkerOptions m -> f (WorkerOptions m)

-- | Creates a green thread from an <tt>IO ()</tt> sub-routine. Depending
--   in options defined in the <a>WorkerOptions</a> record, it will
--   automatically restart this sub-routine in case of failures.
--   
--   See documentation of related functions:
--   
--   <ul>
--   <li><a>buildWorkerOptionsWithDefaults</a></li>
--   <li><a>buildWorkerOptions</a></li>
--   </ul>
forkWorker :: (MonadIO m, HasSupervisor supervisor) => WorkerOptions m -> supervisor m -> m WorkerId

-- | Creates a green thread which monitors other green threads for failures
--   and restarts them using settings defined on <a>SupervisorOptions</a>.
--   
--   See documentation of related functions:
--   
--   <ul>
--   <li><tt>buildSupervisorOptionsWithDefault</tt></li>
--   <li><a>buildSupervisorOptions</a></li>
--   </ul>
forkSupervisor :: (MonadIO m, HasSupervisor parentSupervisor) => SupervisorOptions m -> parentSupervisor m -> m (Supervisor m)

-- | Creates a Capataz record, which holds both a root supervisor and a
--   <a>Teardown</a> to shut down the system. The root supervisor monitors
--   failures on process threads defined with
--   <a>$sel:supervisorProcessSpecList:CapatazOptions</a> or created
--   dynamically using <a>forkWorker</a> or <a>forkSupervisor</a>.
forkCapataz :: (MonadUnliftIO m, MonadIO m) => Text -> (CapatazOptions m -> CapatazOptions m) -> m (Capataz m)

-- | Terminates a <a>Capataz</a> system (all supervised threads) and
--   returns a <a>TeardownResult</a>
terminateCapataz :: MonadIO m => Capataz m -> m TeardownResult

-- | Terminates a <a>Capataz</a> system (all supervised threads)
terminateCapataz_ :: MonadIO m => Capataz m -> m ()

-- | Stops the execution of a green thread being supervised by the given
--   supervisor.
--   
--   <b>IMPORTANT</b> If <a>ProcessId</a> maps to a worker that is
--   configured with a <a>Permanent</a> worker restart strategy, the worker
--   green thread __will be restarted again__.
terminateProcess :: (MonadIO m, HasSupervisor supervisor) => Text -> ProcessId -> supervisor m -> m Bool

-- | Joins the thread of the root supervisor of the given capataz system to
--   the current thread.
joinCapatazThread :: MonadIO m => Capataz m -> m ()

-- | Gets the process identifier of a <a>Supervisor</a>; normally used for
--   termination.
getSupervisorProcessId :: Supervisor m -> ProcessId

-- | Gets the <a>Async</a> of a Supervisor thread.
--   
--   NOTE: There is no way to get the <a>Async</a> value of the root
--   supervisor; this is done on-purpose to avoid error scenarios.
getSupervisorAsync :: Supervisor m -> Async ()

-- | Gets <a>Teardown</a> record of this capataz system.
getCapatazTeardown :: Capataz m -> Teardown

-- | Result from a <a>Teardown</a> sub-routine
data TeardownResult

-- | <a>&amp;</a> is a reverse application operator. This provides
--   notational convenience. Its precedence is one higher than that of the
--   forward application operator <a>$</a>, which allows <a>&amp;</a> to be
--   nested in <a>$</a>.
--   
--   <pre>
--   &gt;&gt;&gt; 5 &amp; (+1) &amp; show
--   "6"
--   </pre>
(&) :: () => a -> a -> b -> b
infixl 1 &

-- | <a>set</a> is a synonym for (<a>.~</a>).
--   
--   Setting the 1st component of a pair:
--   
--   <pre>
--   <a>set</a> <a>_1</a> :: x -&gt; (a, b) -&gt; (x, b)
--   <a>set</a> <a>_1</a> = \x t -&gt; (x, snd t)
--   </pre>
--   
--   Using it to rewrite (<a>&lt;$</a>):
--   
--   <pre>
--   <a>set</a> <a>mapped</a> :: <a>Functor</a> f =&gt; a -&gt; f b -&gt; f a
--   <a>set</a> <a>mapped</a> = (<a>&lt;$</a>)
--   </pre>
set :: () => ASetter s t a b -> b -> s -> t


-- | Convinience module that re-exports modules:
--   
--   <ul>
--   <li><a>Control.Concurrent.Capataz</a></li>
--   <li><a>Control.Concurrent.Capataz.Util</a></li>
--   </ul>
module Capataz

-- | Builds a <a>ProcessSpec</a> that spawns a thread that logs messages
--   written with the returned <a>LogFunc</a>. Use this function when your
--   want your logger to be part of a static supervision tree.
--   
--   <b>IMPORTANT</b> If you use the returned <a>LogFunc</a> to log
--   functions and the <a>ProcessSpec</a> is not used in a supervision
--   tree, your logging won't work and your application will eventually
--   block the current thread when logging.
--   
--   A minimal example:
--   
--   <pre>
--   {--}
--   {--}
--   import RIO
--   import Capataz
--   
--   main :: IO ()
--   main = do
--     logOptions &lt;- logOptionsHandle stdout True
--     (loggerSpec, logFunc) &lt;- buildLogWorkerSpec logOptions "app-logger" 100 id
--     runRIO logFunc $ do
--       bracket (forkCapataz "application" (set supervisorProcessSpecListL [loggerSpec]))
--               terminateCapataz_ $ _capataz -&gt; do
--         logInfo "this log message is written by a dedicated supervised thread"
--         threadDelay 1000100
--   </pre>
buildLogWorkerSpec :: (MonadUnliftIO m, MonadIO m0) => LogOptions -> WorkerName -> Int -> (WorkerOptions m -> WorkerOptions m) -> m0 (ProcessSpec m, LogFunc)

-- | Builds a <a>WorkerOptions</a> record that spawns a thread that logs
--   messages written with the returned <a>LogFunc</a>. Use this function
--   if you want to build a logger thread dynamically via
--   <tt>forkWorker</tt>.
--   
--   <b>IMPORTANT</b> If you use the returned <a>LogFunc</a> to log
--   functions and the <a>WorkerOptions</a> is not used in a
--   <tt>forkWorker</tt> call, your logging won't work and your application
--   will eventually block the current thread when logging.
--   
--   A minimal example:
--   
--   <pre>
--   {--}
--   {--}
--   import RIO
--   import Capataz
--   
--   main :: IO ()
--   main = do
--     logOptions &lt;- logOptionsHandle stdout True
--     (loggerOptions, logFunc) &lt;- buildLogWorkerOptions logOptions "app-logger" 100 id
--     runRIO logFunc $ do
--       bracket (forkCapataz "application" id)
--               terminateCapataz_ $ capataz -&gt; do
--         _workerId &lt;- forkWorker loggerOptions capataz
--         logInfo "this log message is written by a dedicated supervised thread"
--         threadDelay 1000100
--   </pre>
buildLogWorkerOptions :: (MonadUnliftIO m, MonadIO m0) => LogOptions -> WorkerName -> Int -> (WorkerOptions m -> WorkerOptions m) -> m0 (WorkerOptions m, LogFunc)
