Spock-worker-0.3.0.0: Background workers for Spock

Safe HaskellNone
LanguageHaskell2010

Web.Spock.Worker

Contents

Synopsis

Define a Worker

type WorkHandler conn sess st err a = a -> ExceptT (InternalError err) (WebStateM conn sess st) WorkResult Source

Describe how you want jobs in the queue to be performed

data WorkerConfig Source

Configure how the worker handles it's task and define the queue size

data WorkerConcurrentStrategy Source

Configure the concurrent behaviour of a worker. If you want tasks executed concurrently, consider using WorkerConcurrentBounded

data WorkerDef conn sess st err a Source

Define a worker

Constructors

WorkerDef 

Fields

wd_config :: WorkerConfig
 
wd_handler :: WorkHandler conn sess st err a
 
wd_errorHandler :: ErrorHandler conn sess st err a
 

newWorker :: (MonadTrans t, Monad (t (WebStateM conn sess st))) => WorkerDef conn sess st err a -> t (WebStateM conn sess st) (WorkQueue a) Source

Create a new background worker and limit the size of the job queue.

data WorkResult Source

Describes the outcome of a job after completion. You can repeat jobs

Enqueue work

data WorkQueue a Source

The queue containing scheduled jobs

data WorkExecution Source

Describes when a job should be executed

addWork :: MonadIO m => WorkExecution -> a -> WorkQueue a -> m () Source

Add a new job to the background worker. If the queue is full this will block

Error Handeling

data ErrorHandler conn sess st err a Source

Describe how you want to handle errors. Make sure you catch all exceptions that can happen inside this handler, otherwise the worker will crash!

Constructors

ErrorHandlerIO (InternalError err -> a -> IO WorkResult) 
ErrorHandlerSpock (InternalError err -> a -> WebStateM conn sess st WorkResult) 

data InternalError a Source

An error from a worker