postgresql-simple-queue-0.1.0.1: A PostgreSQL backed queue

Safe HaskellNone
LanguageHaskell2010

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.

Synopsis

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

data Options Source #

Final Options used by run.

Entry Points

defaultMain Source #

Arguments

:: (MonadIO m, MonadBaseControl IO m) 
=> Text

Executable name. Used when command line help is printed

-> (Payload -> Int64 -> m ())

Processing function. Takes a Payload to process and the current number of Enqueued Payloads remaining.

-> 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.

run Source #

Arguments

:: (MonadIO m, MonadBaseControl IO m) 
=> (Payload -> Int64 -> m ())

Processing function. Takes a Payload to process and the current number of Enqueued Payloads remaining.

-> 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.