Очереди и асинхронная обработка изображений, трек 1

This commit is contained in:
Queenfish
2026-11-12 21:14:30 +03:00
parent 276dbdad8a
commit 01a5023c6d
102 changed files with 6374 additions and 47 deletions
+37
View File
@@ -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()))