| Copyright | (c) Gargantext 2024-Present |
|---|---|
| License | AGPL |
| Maintainer | gargantext@iscpif.fr |
| Stability | experimental |
| Portability | POSIX |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Async.Worker.Types
Description
Types for worker.
Synopsis
- data State b a = State {
- broker :: Broker b (Job a)
- queueName :: Queue
- name :: String
- performAction :: PerformAction b a
- onMessageReceived :: WorkerJobEvent b a
- onJobFinish :: WorkerJobEvent b a
- onJobTimeout :: WorkerJobEvent b a
- onJobError :: WorkerJobErrorEvent b a
- onWorkerKilledSafely :: WorkerMJobEvent b a
- data Job a = Job {
- job :: a
- metadata :: JobMetadata
- data JobMetadata = JobMetadata {}
- defaultMetadata :: JobMetadata
- data ArchiveStrategy
- data ErrorStrategy
- data TimeoutStrategy
- getJob :: Job a -> a
- jobTimeout :: Job a -> Timeout
- type Timeout = Int
- runAction :: State b a -> BrokerMessage b (Job a) -> IO ()
- type PerformAction b a = State b a -> BrokerMessage b (Job a) -> IO ()
- type WorkerJobEvent b a = Maybe (State b a -> BrokerMessage b (Job a) -> IO ())
- type WorkerJobErrorEvent b a = Maybe (State b a -> BrokerMessage b (Job a) -> SomeException -> IO ())
- type WorkerMJobEvent b a = Maybe (State b a -> Maybe (BrokerMessage b (Job a)) -> IO ())
- type HasWorkerBroker b a = (MessageBroker b (Job a), Typeable a, Typeable b, Show a)
- formatStr :: State b a -> String -> String
- data JobTimeout b a = JobTimeout {
- jtBMessage :: BrokerMessage b (Job a)
- jtTimeout :: Timeout
Main worker state
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
Worker Job is a (defining action to call via $sel:performAction:State)
together with associated JobMetadata.
Constructors
| Job | |
Fields
| |
Job metadata
data JobMetadata Source #
Metadata associated with a job.
Constructors
| JobMetadata | |
Fields
| |
Instances
| FromJSON JobMetadata Source # | |
Defined in Async.Worker.Types | |
| ToJSON JobMetadata Source # | |
Defined in Async.Worker.Types Methods toJSON :: JobMetadata -> Value # toEncoding :: JobMetadata -> Encoding # toJSONList :: [JobMetadata] -> Value # toEncodingList :: [JobMetadata] -> Encoding # omitField :: JobMetadata -> Bool # | |
| Show JobMetadata Source # | |
Defined in Async.Worker.Types Methods showsPrec :: Int -> JobMetadata -> ShowS # show :: JobMetadata -> String # showList :: [JobMetadata] -> ShowS # | |
| Eq JobMetadata Source # | |
Defined in Async.Worker.Types | |
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
Instances
| FromJSON ArchiveStrategy Source # | |
Defined in Async.Worker.Types Methods parseJSON :: Value -> Parser ArchiveStrategy # parseJSONList :: Value -> Parser [ArchiveStrategy] # | |
| ToJSON ArchiveStrategy Source # | |
Defined in Async.Worker.Types Methods toJSON :: ArchiveStrategy -> Value # toEncoding :: ArchiveStrategy -> Encoding # toJSONList :: [ArchiveStrategy] -> Value # toEncodingList :: [ArchiveStrategy] -> Encoding # omitField :: ArchiveStrategy -> Bool # | |
| Show ArchiveStrategy Source # | |
Defined in Async.Worker.Types Methods showsPrec :: Int -> ArchiveStrategy -> ShowS # show :: ArchiveStrategy -> String # showList :: [ArchiveStrategy] -> ShowS # | |
| Eq ArchiveStrategy Source # | |
Defined in Async.Worker.Types Methods (==) :: ArchiveStrategy -> ArchiveStrategy -> Bool # (/=) :: ArchiveStrategy -> ArchiveStrategy -> Bool # | |
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. |
Instances
| FromJSON ErrorStrategy Source # | |
Defined in Async.Worker.Types Methods parseJSON :: Value -> Parser ErrorStrategy # parseJSONList :: Value -> Parser [ErrorStrategy] # | |
| ToJSON ErrorStrategy Source # | |
Defined in Async.Worker.Types Methods toJSON :: ErrorStrategy -> Value # toEncoding :: ErrorStrategy -> Encoding # toJSONList :: [ErrorStrategy] -> Value # toEncodingList :: [ErrorStrategy] -> Encoding # omitField :: ErrorStrategy -> Bool # | |
| Show ErrorStrategy Source # | |
Defined in Async.Worker.Types Methods showsPrec :: Int -> ErrorStrategy -> ShowS # show :: ErrorStrategy -> String # showList :: [ErrorStrategy] -> ShowS # | |
| Eq ErrorStrategy Source # | |
Defined in Async.Worker.Types Methods (==) :: ErrorStrategy -> ErrorStrategy -> Bool # (/=) :: ErrorStrategy -> ErrorStrategy -> Bool # | |
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 |
Instances
| FromJSON TimeoutStrategy Source # | |
Defined in Async.Worker.Types Methods parseJSON :: Value -> Parser TimeoutStrategy # parseJSONList :: Value -> Parser [TimeoutStrategy] # | |
| ToJSON TimeoutStrategy Source # | |
Defined in Async.Worker.Types Methods toJSON :: TimeoutStrategy -> Value # toEncoding :: TimeoutStrategy -> Encoding # toJSONList :: [TimeoutStrategy] -> Value # toEncodingList :: [TimeoutStrategy] -> Encoding # omitField :: TimeoutStrategy -> Bool # | |
| Show TimeoutStrategy Source # | |
Defined in Async.Worker.Types Methods showsPrec :: Int -> TimeoutStrategy -> ShowS # show :: TimeoutStrategy -> String # showList :: [TimeoutStrategy] -> ShowS # | |
| Eq TimeoutStrategy Source # | |
Defined in Async.Worker.Types Methods (==) :: TimeoutStrategy -> TimeoutStrategy -> Bool # (/=) :: TimeoutStrategy -> TimeoutStrategy -> Bool # | |
Job utility functions
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 WorkerJobErrorEvent b a = Maybe (State b a -> BrokerMessage b (Job a) -> SomeException -> 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 #
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 | |
Fields
| |
Instances
| (Show (BrokerMessage b (Job a)), Typeable a, Typeable b) => Exception (JobTimeout b a) Source # | |
Defined in Async.Worker.Types Methods toException :: JobTimeout b a -> SomeException # fromException :: SomeException -> Maybe (JobTimeout b a) # displayException :: JobTimeout b a -> String # | |
| Show (BrokerMessage b (Job a)) => Show (JobTimeout b a) Source # | |
Defined in Async.Worker.Types Methods showsPrec :: Int -> JobTimeout b a -> ShowS # show :: JobTimeout b a -> String # showList :: [JobTimeout b a] -> ShowS # | |