úÎ4Û1“(      !"#$%&'Safe ()*+,-./01234)/01234 ()*+,-./01234NonetThis 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[ A ) can exist in three states in the queue,  , and . A  starts in the X state and is locked so some sort of process can occur with it, usually something in 5*. Once the processing is complete, the  is moved the ' state, which is the terminal state.The JSON value of a payloadÙ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 6. $ do createUserDB userRecord $ $ makeVerificationEmail userRecord  Transition a  to the  state.yAttempt to get a payload and process it. If the function passed in throws an exception return it on the left side of the 7:. Re-add the payload up to some passed in maximum. Return 8 is the payloads+ table is empty otherwise the result is an a% from the payload ingesting function.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  dequeueDb as a 9 transaction.See R for an alternative interface that will automatically return the payload to the  state if an exception occurs. Transition a  to the  state. his functions runs  as a : 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.Get the number of rows in the  state. This function runs  in a 9 transaction.! ;<=>schema retry countpayload processing function? retry count     ;<=>?@      !"#$%&'()*+,-./0123456789:;<=>?=@ABCDBCEFGHIJK4postgresql-simple-queue-1.0.0-CPJe3XzmjSs5d6X6OaWgsH(Database.PostgreSQL.Simple.Queue.Migrate Database.PostgreSQL.Simple.QueuePaths_postgresql_simple_queuemigrateStateEnqueuedDequeuedPayloadpIdpValuepState pAttempts pCreatedAt pModifiedAt PayloadId unPayloadId enqueueDB dequeueDB withPayloadDB getCountDBenqueue tryDequeuedequeue withPayloadgetCount$fFromFieldState$fToFieldState$fFromRowPayload$fToRowPayloadId$fFromRowPayloadId $fEqPayloadId$fShowPayloadId$fFromFieldPayloadId$fToFieldPayloadId $fShowState $fEqState $fOrdState $fEnumState$fBoundedState $fShowPayload $fEqPayloadcatchIOversionbindirlibdirdatadir libexecdir sysconfdir getBinDir getLibDir getDataDir getLibexecDir getSysconfDirgetDataFileNameghc-prim GHC.TypesIO*pg-transact-0.1.0.1-AjFv9uqVJaz8qi2tG8FX1PDatabase.PostgreSQL.TransactrunDBTSerializablebase Data.EitherEitherGHC.BaseNothing0postgresql-simple-0.5.3.0-2v4a7jtkBHgJxGerjee3u3&Database.PostgreSQL.Simple.Transaction ReadCommitted Serializable withSchema notifyName enqueueWithDBretryDB notifyPayload