test_pipeline_job_status_writers.py 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. """Queue status changes stay visible to the pipeline job hooks.
  2. services/pipeline_job_status stores a job's final status from flushes and from
  3. statements run through a session. A status written or a row deleted as raw SQL
  4. text would skip both, and the job would forget whether its copy printed.
  5. """
  6. import re
  7. from pathlib import Path
  8. APP = Path(__file__).resolve().parents[2] / "app"
  9. # Matched across lines: SQL is usually split into string pieces.
  10. RAW_WRITES = re.compile(
  11. r"UPDATE\s+print_queue\b[\s\"']*SET\b[^;)]*?\bstatus\s*=|DELETE\s+FROM\s+print_queue\b",
  12. re.IGNORECASE,
  13. )
  14. # Raw writes that cannot end a job, with why.
  15. ALLOWED = {
  16. # The #1667 migration resets skipped items to pending: not a final status.
  17. "core/database.py": 1,
  18. }
  19. def test_no_raw_sql_ends_or_deletes_a_queue_entry():
  20. found: dict[str, int] = {}
  21. for path in APP.rglob("*.py"):
  22. count = len(RAW_WRITES.findall(path.read_text(encoding="utf-8")))
  23. if count:
  24. found[str(path.relative_to(APP))] = count
  25. assert found == ALLOWED