forked from mtusi2026/mtusi2026lab5
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import asyncio
|
|
import sys
|
|
|
|
from app.cache import make_cache
|
|
from app.db import db
|
|
from app.storage import Storage
|
|
|
|
|
|
async def main():
|
|
await db.connect()
|
|
cache = make_cache()
|
|
storage = Storage(db.pool, cache)
|
|
|
|
print("[lease_checker] started", flush=True)
|
|
while True:
|
|
try:
|
|
expired_jobs = await storage.get_expired_jobs()
|
|
for job in expired_jobs:
|
|
print(f"[lease_checker] requeueing expired job {job['job_id']}", flush=True)
|
|
await storage.reset_job_status(str(job["job_id"]))
|
|
job_payload = {
|
|
"schema_version": 1,
|
|
"job_id": str(job["job_id"]),
|
|
"type": "attachment.process.v1",
|
|
"attachment_id": str(job["attachment_id"]),
|
|
"pipeline_version": job["pipeline_version"],
|
|
"attempt": job["attempt"],
|
|
"created_at": "2026-01-01T00:00:00Z",
|
|
}
|
|
await storage.create_outbox(job_payload)
|
|
except Exception as e:
|
|
print(f"[lease_checker] error: {e}", flush=True)
|
|
await asyncio.sleep(10)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(asyncio.run(main())) |