Skip to main content

claim

Function claim 

Source
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 + UPDATE inside a transaction.
  • SQLite: single UPDATE … RETURNING inside a conn.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 no BEGIN IMMEDIATE needed).