from pathlib import Path import sys import time sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tests")) from client import Client, check from check_recovery import compose, job_for def main(): c = Client() actor, _, _, chat = c.bootstrap() compose("stop", "worker") attachment, _ = c.attachment(actor, chat) job_id = job_for(attachment) code = f""" from storage import Store s = Store() try: with s.pool.connection() as db: db.execute('UPDATE attachments SET status=%s,error_code=%s WHERE id=%s', ('failed','processing_failed','{attachment["id"]}')) db.execute('UPDATE jobs SET finished=true WHERE id=%s', ('{job_id}',)) finally: s.close() """ try: compose("exec", "-T", "-w", "/app/src", "api-a", "python", "-c", code) compose("exec", "-T", "api-a", "python", "src/replay_job.py", job_id) finally: compose("start", "worker") ready = c.wait_ready(actor, attachment) check(ready["status"] == "ready", "replay failed") print("PASS: explicit failed-job replay completes original attachment") if __name__ == "__main__": main()