feat: add fake acquisition pipeline

This commit is contained in:
Jonathan
2026-07-10 17:04:41 +02:00
parent fc1229b885
commit d441d0561f
2 changed files with 56 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
import time
import psycopg
# (state, currentStage) pairs the job moves through, in order, after claim.
_STAGES = [
("matched", "rank"),
("downloading", "download"),
("tagging", "tag"),
("imported", "import"),
]
def _set_state(conn: psycopg.Connection, job_id: str, state: str, stage: str) -> None:
with conn.cursor() as cur:
cur.execute(
'UPDATE "Job" SET state = %s, "currentStage" = %s, "updatedAt" = now() WHERE id = %s',
(state, stage, job_id),
)
conn.commit()
def run_pipeline(conn: psycopg.Connection, job_id: str, stage_delay: float = 0.0) -> None:
"""Fake acquisition: walk the claimed job through to 'imported'."""
for state, stage in _STAGES:
if stage_delay:
time.sleep(stage_delay)
_set_state(conn, job_id, state, stage)
with conn.cursor() as cur:
cur.execute(
'UPDATE "Request" SET status = \'completed\' '
'WHERE id = (SELECT "requestId" FROM "Job" WHERE id = %s)',
(job_id,),
)
conn.commit()