Back to the room

Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works

Code Observatory / Source

Claim a durable job

Queue state lives in the database. Redis only wakes workers.

PINNED SOURCE Copied from the repository at this commit. Source, not an execution.

PHAROS at 975a38dMIT license

claimbackend/app/codeintel/jobs.py, lines 118–141Open source
def claim(db: Session, job_id: uuid.UUID, worker_id: str, model: JobModel = IngestionJob):    """Atomically move a queued job to running. None if someone else got it."""    now = utcnow()    result = db.execute(        update(model)        .where(            model.id == job_id,            model.status == "queued",            or_(model.available_at.is_(None), model.available_at <= now),        )        .values(            status="running",            attempts=model.attempts + 1,            worker_id=worker_id,            started_at=now,            heartbeat_at=now,            error=None,            error_kind=None,        )    )    db.commit()    if result.rowcount != 1:        return None    return db.get(model, job_id)

Where this comes from

Commit
975a38d5d17839c26ee219295a5be6ac66b6d910
File
backend/app/codeintel/jobs.py
Lines
118–141
Git blob
54c9a5d84ee5feda5176c3e05d0aa9a7d46f6016
License
MIT, © 2024–2026 Pharos Contributors. Notice

Read it on GitHub at this commit

Check it yourself

From a clone of the repository, the first command prints the blob above and the second prints these lines.

git rev-parse 975a38d:backend/app/codeintel/jobs.py
git show 975a38d:backend/app/codeintel/jobs.py | sed -n '118,141p'