packages feed

hasql-queue 1.0.1 → 1.0.1.1

raw patch · 4 files changed

+22/−40 lines, 4 filesdep +postgresql-libpqdep +postgresql-libpq-notifydep −hasql-notifications

Dependencies added: postgresql-libpq, postgresql-libpq-notify

Dependencies removed: hasql-notifications

Files

CHANGELOG.md view
@@ -1,3 +1,6 @@ Changelog for hasql-queue-- 1.0.0.0+- 1.0.1.1+  - Fixed cabal meta data and copyright++- 1.0.1   - First release!
benchmarks/Main.hs view
@@ -75,13 +75,13 @@         enqueueInsertStatement =           statement (fromIntegral initialEnqueueCount) $ Statement enqueueInsertSql (E.param $ E.nonNullable E.int4) D.noResult False -    withResource pool $ run enqueueInsertStatement+    _ <- withResource pool $ run enqueueInsertStatement      let dequeueInsertSql = "INSERT INTO payloads (attempts, state, value) SELECT 0, 'dequeued', g.value FROM generate_series(1, $1) AS g (value)"         dequeueInsertStatement =           statement (fromIntegral initialDequeueCount) $ Statement dequeueInsertSql (E.param $ E.nonNullable E.int4) D.noResult False -    withResource pool $ run dequeueInsertStatement+    _ <- withResource pool $ run dequeueInsertStatement      withResource pool $ \conn -> void $ run (sql "VACUUM FULL ANALYZE") conn     putStrLn "Finished VACUUM FULL ANALYZE"
hasql-queue.cabal view
@@ -4,40 +4,15 @@ -- -- see: https://github.com/sol/hpack ----- hash: 2c8109092a14882df219b99da03aea13b68292c07f409a58fa68028d6f263eb1+-- hash: 1e85f1ecfea2da607af0d7d470a2487f040dbe1020c661774ca3ebbaec5fcf34  name:           hasql-queue-version:        1.0.1+version:        1.0.1.1 synopsis:       A PostgreSQL backed queue-description:    This module utilize 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' "queue_schema" $ 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 "queue" 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 "queue" conn $ pId payload-                >-                > To support multiple queues in the same database, the API expects a table name string-                > to determine which queue tables to use.+description:    A PostgreSQL backed queue. Please see README.md category:       Web-homepage:       https://github.com/jfischoff/postgresql-queue#readme-bug-reports:    https://github.com/jfischoff/postgresql-queue/issues+homepage:       https://github.com/jfischoff/hasql-queue#readme+bug-reports:    https://github.com/jfischoff/hasql-queue/issues author:         Jonathan Fischoff maintainer:     jonathangfischoff@gmail.com copyright:      2020 Jonathan Fischoff@@ -51,7 +26,7 @@  source-repository head   type: git-  location: https://github.com/jfischoff/postgresql-queue+  location: https://github.com/jfischoff/hasql-queue  library   exposed-modules:@@ -71,9 +46,10 @@     , bytestring     , exceptions     , hasql-    , hasql-notifications     , here     , monad-control+    , postgresql-libpq+    , postgresql-libpq-notify >=0.2.0.0     , random     , stm     , text@@ -98,10 +74,11 @@     , cryptohash-sha1     , exceptions     , hasql-    , hasql-notifications     , hasql-queue     , here     , monad-control+    , postgresql-libpq+    , postgresql-libpq-notify >=0.2.0.0     , random     , resource-pool     , stm@@ -131,13 +108,14 @@     , cryptohash-sha1     , exceptions     , hasql-    , hasql-notifications     , hasql-queue     , here     , hspec     , hspec-core     , hspec-expectations-lifted     , monad-control+    , postgresql-libpq+    , postgresql-libpq-notify >=0.2.0.0     , random     , resource-pool     , split
src/Hasql/Queue/Internal.hs view
@@ -2,7 +2,7 @@ import qualified Hasql.Encoders as E import qualified Hasql.Decoders as D import           Hasql.Session-import           Hasql.Notification+import           Database.PostgreSQL.LibPQ.Notify import           Control.Monad (unless) import           Data.Function(fix) import           Hasql.Connection@@ -14,6 +14,7 @@ import           Control.Exception import           Control.Monad.IO.Class import           Data.Typeable+import qualified Database.PostgreSQL.LibPQ as PQ  -- | A 'Payload' can exist in three states in the queue, 'Enqueued', --   and 'Dequeued'. A 'Payload' starts in the 'Enqueued' state and is locked@@ -210,8 +211,8 @@ -- Block until a payload notification is fired. Fired during insertion. notifyPayload :: ByteString -> Connection -> IO () notifyPayload channel conn = fix $ \restart -> do-  Notification {..} <- either throwIO pure =<< getNotification conn-  unless (notificationChannel == channel) restart+  PQ.Notify {..} <- either throwIO pure =<< withLibPQConnection conn getNotification+  unless (notifyRelname == channel) restart  -- | To aid in observability and white box testing data WithNotifyHandlers = WithNotifyHandlers