haskell-bee-0.1.0.0: A lightweight library for asynchronous job workers with multiple broker backends
Copyright(c) Gargantext 2024-Present
LicenseAGPL
Maintainergargantext@iscpif.fr
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageHaskell2010

Async.Worker.Types

Description

Types for worker.

Synopsis

Main worker state

data State b a Source #

Main state for a running worker (b is Broker, a is the underlying message).

a is the underlying message specification and is implementation-dependent, e.g. can be of JSON form

{"function": ..., "arguments": [...]}

Job a is worker's wrapper around that message with metadata (corresponds to broker Message b a). BrokerMessage 'b a, on the other hand, is what we get when the broker reads that message).

Note that our underlying Broker handles messages of type Job a.

Constructors

State 

Fields

Job wrapped in metadata

data Job a Source #

Worker Job is a (defining action to call via $sel:performAction:State) together with associated JobMetadata.

Constructors

Job 

Fields

Instances

Instances details
FromJSON a => FromJSON (Job a) Source # 
Instance details

Defined in Async.Worker.Types

ToJSON a => ToJSON (Job a) Source # 
Instance details

Defined in Async.Worker.Types

Methods

toJSON :: Job a -> Value #

toEncoding :: Job a -> Encoding #

toJSONList :: [Job a] -> Value #

toEncodingList :: [Job a] -> Encoding #

omitField :: Job a -> Bool #

Show a => Show (Job a) Source # 
Instance details

Defined in Async.Worker.Types

Methods

showsPrec :: Int -> Job a -> ShowS #

show :: Job a -> String #

showList :: [Job a] -> ShowS #

Eq a => Eq (Job a) Source # 
Instance details

Defined in Async.Worker.Types

Methods

(==) :: Job a -> Job a -> Bool #

(/=) :: Job a -> Job a -> Bool #

Job metadata

data JobMetadata Source #

Metadata associated with a job.

Constructors

JobMetadata 

Fields

defaultMetadata :: JobMetadata Source #

For a typical Job it's probably sane to just archive it no matter how it finished.

Strategies for handling finished, errored, timed-out jobs

data ArchiveStrategy Source #

Strategy for archiving finished jobs

Constructors

ASDelete

Delete message when it's done

ASArchive

Archive message when it's done

data ErrorStrategy Source #

Strategy for handling jobs with errors

Constructors

ESDelete

Delete job when it threw an error

ESArchive

Archive job when it threw an error

ESRepeatNElseArchive Int

Try to repeat the job when an error ocurred (at most N times), otherwise archive the job.

data TimeoutStrategy Source #

Strategy for handling job timeouts

Constructors

TSDelete

Delete job when it timed out

TSArchive

Archive job when it timed out

TSRepeat

Repeat job when it timed out (infinitely)

TSRepeatNElseArchive Int

Repeat job when it timed out (at most N times), otherwise archive it

TSRepeatNElseDelete Int

Repeat job when it timed out (at most N times), otherwise delete it

Job utility functions

getJob :: Job a -> a Source #

Given worker Job a, return the a part

jobTimeout :: Job a -> Timeout Source #

For a given Job, return it's $sel:timeout:JobMetadata value from JobMetadata.

runAction :: State b a -> BrokerMessage b (Job a) -> IO () Source #

Helper function to call an action for given worker, for a BrokerMessage.

Actions that the worker will perform

type PerformAction b a = State b a -> BrokerMessage b (Job a) -> IO () Source #

Callback definition (what to execute when a message arrives)

Events emitted during job lifetime

type WorkerJobEvent b a = Maybe (State b a -> BrokerMessage b (Job a) -> IO ()) Source #

type WorkerMJobEvent b a = Maybe (State b a -> Maybe (BrokerMessage b (Job a)) -> IO ()) Source #

Other useful types and functions

type HasWorkerBroker b a = (MessageBroker b (Job a), Typeable a, Typeable b, Show a) Source #

TODO Show a could be removed. Any logging can be done as part of on events in State.

formatStr :: State b a -> String -> String Source #

Helper function to format a string with worker name (for logging)

data JobTimeout b a Source #

An exception, thrown when job times out

Constructors

JobTimeout 

Instances

Instances details
(Show (BrokerMessage b (Job a)), Typeable a, Typeable b) => Exception (JobTimeout b a) Source # 
Instance details

Defined in Async.Worker.Types

Show (BrokerMessage b (Job a)) => Show (JobTimeout b a) Source # 
Instance details

Defined in Async.Worker.Types

Methods

showsPrec :: Int -> JobTimeout b a -> ShowS #

show :: JobTimeout b a -> String #

showList :: [JobTimeout b a] -> ShowS #