Spock-worker-0.1.0.1: Background workers for Spock

Safe HaskellNone

Web.Spock.Worker

Contents

Synopsis

Worker

data WorkQueue a Source

The queue containing scheduled jobs

type WorkHandler conn sess st a = a -> ErrorT InternalError (WebStateM conn sess st) WorkResultSource

Describe how you want jobs in the queue to be performed

newWorker :: Int -> WorkHandler conn sess st a -> ErrorHandler a -> SpockM conn sess st (WorkQueue a)Source

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

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

data WorkExecution Source

Describes when a job should be executed

data WorkResult Source

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

Error Handeling

type ErrorHandler a = InternalError -> a -> IO WorkResultSource

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