Back to the room

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

Code Observatory / function

queue_summary

codeintel.jobs.queue_summary

PINNED SOURCE Source and edges from the index at this commit. An execution appears only where one was recorded.

PHAROS at 975a38dMIT license

Around this symbol

Search all symbols

Loading

Calls (1)
SymbolFileResolved by
utcnowjobs.pysame file
Inside (1)
SymbolFileResolved by
jobsjobs.pysame file
codeintel.jobs.queue_summarybackend/app/codeintel/jobs.py, lines 180–208Open source
def queue_summary(db: Session, stale_after_seconds: int, model: JobModel = IngestionJob) -> dict:    """Worker health as seen from the durable job table.    ``degraded`` when a running job stopped heartbeating, or a queued job has    waited longer than ``stale_after_seconds`` (no worker is picking jobs up).    """    now = utcnow()    cutoff = now - timedelta(seconds=stale_after_seconds)    def count(*where) -> int:        return db.execute(select(func.count()).select_from(model).where(*where)).scalar_one()    oldest = db.execute(        select(func.min(model.created_at)).where(model.status == "queued")    ).scalar_one()    if oldest is not None and oldest.tzinfo is None:        oldest = oldest.replace(tzinfo=now.tzinfo)    summary = {        "queued": count(model.status == "queued"),        "running": count(model.status == "running"),        "stale_running": count(model.status == "running", model.heartbeat_at < cutoff),        "failed_last_24h": count(model.status == "failed", model.finished_at >= now - timedelta(days=1)),        "oldest_queued_seconds": (now - oldest).total_seconds() if oldest is not None else None,    }    stuck = summary["stale_running"] > 0 or (        summary["oldest_queued_seconds"] is not None and summary["oldest_queued_seconds"] > stale_after_seconds    )    summary["status"] = "degraded" if stuck else "healthy"    return summary

What the index recorded

Signature
def queue_summary(db: Session, stale_after_seconds: int, model: JobModel) -> dict:
File
backend/app/codeintel/jobs.py
Lines
180–208
Parser
python-ast
Git blob
54c9a5d84ee5feda5176c3e05d0aa9a7d46f6016
Call sites
11 named, 3 resolved, 8 left unlinked
Outside this subset
4 more edges reach code outside the graph shown here

Read it on GitHub at this commit