forked from mtusi2026/mtusi2026lab5
Очереди и асинхронная обработка изображений, трек 1
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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()))
|
||||
Reference in New Issue
Block a user