Safe Haskell | None |
---|---|
Language | Haskell2010 |
Database.PostgreSQL.Simple.Queue.Main
Contents
Description
This module provides a simple way to create executables for consuming queue
payloads. It provides a defaultMain
function which takes in a executable
name and processing function. It returns a main function which will parse
database options on from the command line and spawn a specified number of
worker threads.
Here is a simple example that logs out queue payloads
defaultMain "queue-logger" $ payload count -> do print payload print count
The worker threads do not attempt to handle exceptions. If an exception is
thrown on any threads, all threads are cancel and defaultMain
returns. The
assumption is the queue executable will get run by a process watcher that
can log failures.
For a more complicated example, see the code for the async-email-example
documented in EmailQueue
.
- data PartialOptions
- data Options
- completeOptions :: PartialOptions -> Either [String] Options
- defaultMain :: (MonadIO m, MonadBaseControl IO m) => Text -> (Payload -> Int64 -> m ()) -> m ()
- run :: forall m. (MonadIO m, MonadBaseControl IO m) => (Payload -> Int64 -> m ()) -> Options -> m ()
Options
data PartialOptions Source #
The PartialOptions
provide a Monoid
for combining options used by
defaultMain
. The following command line arguments are used to
construct a PartialOptions
--thread-count INT Either a connection string --connectString ARG or individual db properties are provided --host STRING --port INT --user STRING --password STRING --database STRING
Instances
Eq PartialOptions Source # | |
Show PartialOptions Source # | |
Monoid PartialOptions Source # | |
Default PartialOptions Source # | The default |
ParseRecord PartialOptions Source # | |
completeOptions :: PartialOptions -> Either [String] Options Source #
Convert a PartialOptions
to a final Options
Entry Points
Arguments
:: (MonadIO m, MonadBaseControl IO m) | |
=> Text | Executable name. Used when command line help is printed |
-> (Payload -> Int64 -> m ()) | Processing function. Takes a |
-> m () |
This function is a helper for creating queue consumer executables.
It takes in a executable
name and processing function. It returns a main function which will parse
database options on from the command line and spawn a specified number of
worker threads. See PartialOptions
for command line documentation.
Here is a simple example that logs out queue payloads
defaultMain "queue-logger" $ payload count -> do print payload print count
The worker threads do not attempt to handle exceptions. If an exception is
thrown on any threads, all threads are cancel and defaultMain
returns. The
assumption is the queue executable will get run by a process watcher that
can log failures.
For a more complicated example, see the code for the async-email-example
documented in EmailQueue
.
Arguments
:: (MonadIO m, MonadBaseControl IO m) | |
=> (Payload -> Int64 -> m ()) | Processing function. Takes a |
-> Options | Options for thread creation and db connections. |
-> m () |
run
is called by defaultMain
after command line argument parsing
is performed. Useful is wants to embed consumer threads inside a
larger application.