pub async fn claim(
conn: &DatabaseConnection,
queue: &str,
worker_id: &str,
) -> Result<Option<JobRow>, Error>Expand description
Atomically claim one pending job from queue.
Returns None when the queue is empty or all eligible jobs are locked by
another worker (Postgres). Uses:
- Postgres:
SELECT … FOR UPDATE SKIP LOCKED+UPDATEinside a transaction. - SQLite: single
UPDATE … RETURNINGinside aconn.begin()transaction so every statement is pinned to one pooled connection; the write lock is taken on the UPDATE itself (no prior read to upgrade, so noBEGIN IMMEDIATEneeded).