()
| 33 | |
| 34 | |
| 35 | def process_next_job() -> bool: |
| 36 | with SessionLocal() as session: |
| 37 | job = claim_next_queued_job(session) |
| 38 | |
| 39 | if not job: |
| 40 | return False |
| 41 | |
| 42 | job_id = job.id |
| 43 | |
| 44 | clean_dir(str(TEMP_DIR)) |
| 45 | clean_dir(str(SUBTITLES_DIR)) |
| 46 | |
| 47 | try: |
| 48 | result_path = run_generation_pipeline( |
| 49 | data=job.payload, |
| 50 | is_cancelled=lambda: _job_cancelled(job_id), |
| 51 | on_log=lambda message, level: _log_event(job_id, message, level), |
| 52 | ) |
| 53 | with SessionLocal() as session: |
| 54 | mark_completed(session, job_id, result_path) |
| 55 | except PipelineCancelled as err: |
| 56 | with SessionLocal() as session: |
| 57 | mark_cancelled(session, job_id, str(err)) |
| 58 | except Exception as err: |
| 59 | with SessionLocal() as session: |
| 60 | mark_failed(session, job_id, str(err)) |
| 61 | |
| 62 | return True |
| 63 | |
| 64 | |
| 65 | def main() -> None: |
no test coverage detected