| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
IHP.Job.Queue.Fetch
Synopsis
- fetchNextJob :: (job ~ GetModelByTableName (GetTableName job), FromRowHasql job, Show (PrimaryKey (GetTableName job)), Table job) => Pool -> UUID -> IO (Maybe job)
- pendingJobConditionSQL :: Text
Documentation
fetchNextJob :: (job ~ GetModelByTableName (GetTableName job), FromRowHasql job, Show (PrimaryKey (GetTableName job)), Table job) => Pool -> UUID -> IO (Maybe job) Source #
Lock and fetch the next available job. In case no job is available returns Nothing.
The lock is set on the job row in an atomic way.
The job status is set to JobStatusRunning, lockedBy will be set to the worker id and the attemptsCount is incremented.
Example: Locking a SendMailJob
let workerId :: UUID = "faa5ba30-1d76-4adf-bf01-2d1f95cddc04" job <- fetchNextJob @SendMailJob pool workerId
After you're done with the job, call jobDidFail or jobDidSucceed to make it available to the queue again.
pendingJobConditionSQL :: Text Source #
Shared WHERE condition for fetching pending jobs as a SQL text fragment. Matches jobs that are either not started or in retry state, not locked, and whose run_at time has passed. Enum values are inlined as SQL string literals (PostgreSQL casts them to job_status).