immortal-worker-0.1.0.0: Create worker threads that logs exceptions and restarts.

Copyright(c) Anton Gushcha (ncrashed) 2020
LicenseMIT
Maintainerncrashed@gmail.com
Stabilityexperimental
PortabilityPortable
Safe HaskellNone
LanguageHaskell2010

Control.Immortal.Worker

Description

Here is a longer description of this module, containing some commentary with some markup.

Typical usage:

worker "supervisor" $ const $ forever $ do
  logInfoN "Supervisor started"
  let subworkers = [
          subworker1
        , subworker2
        ]
  traverse_ (isolate_ "subworker") subworkers
  liftIO $ threadDelay 10_000_000
Synopsis

Documentation

workerWith Source #

Arguments

:: (MonadUnliftIO m, MonadLogger m) 
=> (String -> SomeException -> m ())

Action to perform before worker restart

-> String

Worker label for thred

-> (Thread -> m ())

Worker action (no looping is added)

-> m Thread 

Start immortal worker that logs on exceptions and restarts.

Note that action is not looped implicitly. Add forever into action manually to achive this.

worker :: (MonadUnliftIO m, MonadLogger m) => String -> (Thread -> m ()) -> m Thread Source #

Helper that starts new immortal thread with logging of errors

isolate :: (MonadUnliftIO m, MonadLogger m, NFData a) => String -> a -> m a -> m a Source #

If computation fails, print log and return default value.

isolate_ :: (MonadUnliftIO m, MonadLogger m) => String -> m () -> m () Source #

Same as isolate but returns empty tuple