29 lines
735 B
Python
29 lines
735 B
Python
import time
|
|
|
|
from lyra_worker.claim import claim_next
|
|
from lyra_worker.db import connect
|
|
from lyra_worker.pipeline import run_pipeline
|
|
|
|
IDLE_SLEEP = 2.0
|
|
STAGE_DELAY = 1.0 # visible progress in the UI
|
|
|
|
|
|
def run_forever() -> None:
|
|
conn = connect()
|
|
print("worker: waiting for jobs", flush=True)
|
|
try:
|
|
while True:
|
|
job_id = claim_next(conn)
|
|
if job_id is None:
|
|
time.sleep(IDLE_SLEEP)
|
|
continue
|
|
print(f"worker: claimed job {job_id}", flush=True)
|
|
run_pipeline(conn, job_id, stage_delay=STAGE_DELAY)
|
|
print(f"worker: imported job {job_id}", flush=True)
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run_forever()
|