BSD-3-Clause licensed by Jonathan Fischoff
Maintained by [email protected]

Module documentation for

This version can be pinned in stack with:[email protected]:1c2b7ca4005f7a64fb9e5f8d46c1fabedb8071ed34d21d8a6693481519fcf51e,2789


This module utilizes PostgreSQL to implement a durable queue for efficently processing arbitrary payloads which can be represented as JSON.

Typically a producer would enqueue a new payload as part of larger database transaction

createAccount userRecord = do
  runDBTSerializable $ do
    createUserDB userRecord
    enqueueDB $ makeVerificationEmail userRecord

In another thread or process, the consumer would drain the queue.

  forever $ do
    -- Attempt get a payload or block until one is available
    payload <- lock conn

    -- Perform application specifc parsing of the payload value
    case fromJSON $ pValue payload of
      Success x -> sendEmail x -- Perform application specific processing
      Error err -> logErr err

    -- Remove the payload from future processing
    dequeue conn $ pId payload


stack install postgresql-simple-queue


This package was discussed in the blog Testing PostgreSQL for Fun