feat: add worker loop and production Dockerfiles
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
tests
|
||||
__pycache__
|
||||
*.pyc
|
||||
@@ -0,0 +1,6 @@
|
||||
FROM python:3.12-slim
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
COPY lyra_worker ./lyra_worker
|
||||
CMD ["python", "-m", "lyra_worker.main"]
|
||||
@@ -0,0 +1,28 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user