úÎTÛQ86      !"#$%&'()*+,-./012345NonetThis function creates a table and enumeration type that is appriopiate for the queue. The following sql is used. CREATE TYPE state_t AS ENUM (enqueued, locked, dequeuedh); CREATE TABLE payloads ( id uuid PRIMARY KEY , value jsonb NOT NULL , state state_t NOT NULL DEFAULT enqueuedÿ$ , created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT clock_timestamp() , modified_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT clock_timestamp() ); CREATE INDEX state_idx ON payloads (state); CREATE OR REPLACE FUNCTION update_row_modified_function_() RETURNS TRIGGER AS $$ BEGIN -- ASSUMES the table has a column named exactly "modified_at". -- Fetch date-time of actual current moment from clock, -- rather than start of statement or start of transaction. NEW.modified_at = clock_timestamp(); RETURN NEW; END; $$ language plpgsql; None !":IT[ The JSON value of a payloadA ) can exist in three states in the queue,  ,   and  . A  starts in the   state and is  D so some sort of process can occur with it, usually something in 6*. Once the processing is complete, the  is moved the  ' state, which is the terminal state.ÙEnqueue a new JSON value into the queue. This particularly function can be composed as part of a larger database transaction. For instance, a single transaction could create a user and enqueue a email message. % createAccount userRecord = do 7. $ do createUserDB userRecord $ $ makeVerificationEmail userRecord Return a the oldest  in the   state, or 8¸ if there are no payloads. This function is not necessarily useful by itself, since there are not many use cases where it needs to be combined with other transactions. See a the IO API version, or for a blocking version utilizing PostgreSQL's NOTIFY and LISTEN, see  Transition a  from the   state to the  ~ state. Useful for responding to asynchronous exceptions during a unexpected shutdown. In general the IO API version, K, is probably more useful. The DB version is provided for completeness. Transition a  to the   state.Get the number of rows in the   state.-Enqueue a new JSON value into the queue. See T for a version which can be composed with other queries in a single transaction.Return a the oldest  in the   state or 8h if there are no payloads. For a blocking version utilizing PostgreSQL's NOTIFY and LISTEN, see . This functions runs  as a 9 transaction.Return the oldest  in the  Þ state or block until a payload arrives. This function utilizes PostgreSQL's LISTEN and NOTIFY functionality to avoid excessively polling of the DB while waiting for new payloads, without scarficing promptness. Transition a  from the   state to the  x state. Useful for responding to asynchronous exceptions during a unexpected shutdown. For a DB API version see  Transition a  to the   state. his functions runs  as a 9 transaction.Get the number of rows in the   state. This function runs  in a : transaction.! ;<=     ;<=None !"#0:<=T[*Final Options used by ..+The + provide a ># for combining options used by -C. The following command line arguments are used to construct a + É --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 , Convert a + to a final *-ÿ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 + for command line documentation.5Here is a simple example that logs out queue payloads R 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 -k returns. The assumption is the queue executable will get run by a process watcher that can log failures.XFor a more complicated example, see the code for the async-email-example documented in ... is called by - after command line argument parsing is performed. Useful is wants to embed consumer threads inside a larger application.0 The default ?5 is 1. The default db options are specified in *@ABC+D?EF,-:Executable name. Used when command line help is printedProcessing function. Takes a ) to process and the current number of   s remaining..Processing function. Takes a ) to process and the current number of   s remaining./Options for thread creation and db connections./01*+,-.+*,-.*@ABC+D?EF,-./01NoneG       !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFDEGHIJABKL0MNOPQR6postgresql-simple-queue-0.4.0.0-4id98qVl869LW4aQAYESUD(Database.PostgreSQL.Simple.Queue.Migrate Database.PostgreSQL.Simple.Queue%Database.PostgreSQL.Simple.Queue.Main4Database.PostgreSQL.Simple.Queue.Examples.EmailQueue EmailQueue"Database.PostgreSQL.Simple.OptionsPartialOptionsmigratePayloadpIdpValuepState pCreatedAt pModifiedAtStateEnqueuedLockedDequeued PayloadId unPayloadId enqueueDB tryLockDBunlockDB dequeueDB getCountDBenqueuetryLocklockunlockdequeuegetCount$fFromRowPayload$fFromFieldState$fToFieldState$fToRowPayloadId$fFromRowPayloadId $fEqPayloadId$fShowPayloadId$fFromFieldPayloadId$fToFieldPayloadId $fShowState $fEqState $fOrdState $fEnumState$fBoundedState $fShowPayload $fEqPayloadOptionscompleteOptions defaultMainrun$fParseRecordPartialOptions$fDefaultPartialOptions$fMonoidPartialOptions$fShowPartialOptions$fEqPartialOptions $fShowOptions $fEqOptionsghc-prim GHC.TypesIO*pg-transact-0.1.0.1-HaoSKcaqqHwLGJHdHFNrKaDatabase.PostgreSQL.TransactrunDBTSerializablebaseGHC.BaseNothing/postgresql-simple-0.5.3.0-506pMDhpFXUYO6OgD5Fqr&Database.PostgreSQL.Simple.Transaction Serializable ReadCommitted withSchema notifyName notifyPayloadMonoid threadCount oThreadCount oDBOptions oSchemaName dbOptions schemaName