| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
IHP.Job.Queue.Watch
Synopsis
- watchForJob :: (?context :: context, HasField "logger" context Logger) => Pool -> PGListener -> Text -> Int -> TBQueue JobWorkerProcessMessage -> ResourceT IO (Subscription, ReleaseKey)
- watchForJobWithPollerTriggerRepair :: (?context :: context, HasField "logger" context Logger) => Bool -> Pool -> PGListener -> Text -> Int -> TBQueue JobWorkerProcessMessage -> ResourceT IO (Subscription, ReleaseKey)
- pollForJob :: (?context :: context, HasField "logger" context Logger) => Bool -> Pool -> Text -> Int -> TBQueue JobWorkerProcessMessage -> ResourceT IO ReleaseKey
- notificationTriggersHealthy :: Pool -> Text -> IO Bool
- ensureNotificationTriggers :: (?context :: context, HasField "logger" context Logger) => Pool -> Text -> IO ()
- createNotificationTriggerSQL :: ByteString -> Text
- channelName :: ByteString -> ByteString
Documentation
watchForJob :: (?context :: context, HasField "logger" context Logger) => Pool -> PGListener -> Text -> Int -> TBQueue JobWorkerProcessMessage -> ResourceT IO (Subscription, ReleaseKey) Source #
Calls a callback every time something is inserted, updated or deleted in a given database table.
In the background this function creates a database trigger to notify this function about table changes using pg_notify. When there are existing triggers, it will silently recreate them. So this will most likely not fail.
This function returns a Async. Call cancel on the async to stop watching the database.
Example:
watchInsertOrUpdateTable "projects" do
putStrLn "Something changed in the projects table"Now insert something into the projects table. E.g. by running make psql and then running INSERT INTO projects (id, name) VALUES (DEFAULT, 'New project');
You will see that "Something changed in the projects table" is printed onto the screen.
watchForJobWithPollerTriggerRepair :: (?context :: context, HasField "logger" context Logger) => Bool -> Pool -> PGListener -> Text -> Int -> TBQueue JobWorkerProcessMessage -> ResourceT IO (Subscription, ReleaseKey) Source #
Like watchForJob but allows enabling a poller-side trigger integrity check.
Useful in development to recover from missing triggers after `make db`.
pollForJob :: (?context :: context, HasField "logger" context Logger) => Bool -> Pool -> Text -> Int -> TBQueue JobWorkerProcessMessage -> ResourceT IO ReleaseKey Source #
Periodically checks the queue table for open jobs. Calls the callback if there are any.
watchForJob only catches jobs when something is changed on the table. When a job is scheduled
with a runAt in the future, and no other operation is happening on the queue, the database triggers
will not run, and so watchForJob cannot pick up the job even when runAt is now in the past.
This function returns a Async. Call cancel on the async to stop polling the database.
ensureNotificationTriggers :: (?context :: context, HasField "logger" context Logger) => Pool -> Text -> IO () Source #
createNotificationTriggerSQL :: ByteString -> Text Source #
Returns a SQL script to create the notification trigger.
Wrapped in a DO $$ block with EXCEPTION handler because concurrent requests can race to CREATE OR REPLACE the same function, causing PostgreSQL to throw 'tuple concurrently updated' (SQLSTATE XX000). This is safe to ignore: the other connection's CREATE OR REPLACE will have succeeded.
channelName :: ByteString -> ByteString Source #
Retuns the event name of the event that the pg notify trigger dispatches