Добавить варианты изображений, очистку staging, replay и сценарии отказа

This commit is contained in:
2026-11-20 06:18:12 +03:00
parent a0ec26d96d
commit e376ede0a2
12 changed files with 258 additions and 1 deletions
+43
View File
@@ -0,0 +1,43 @@
"""Локальные операции над реестром заданий."""
import argparse
import json
from uuid import UUID
from botocore.exceptions import BotoCoreError, ClientError
from src import jobs
from src.storage import storage, timestamp
def main():
parser = argparse.ArgumentParser()
parser.add_argument('action', choices=('failed', 'replay'))
parser.add_argument('attachment_id', type=UUID, nargs='?')
args = parser.parse_args()
if args.action == 'replay' and args.attachment_id is None:
parser.error('replay requires attachment_id')
storage.pool.open(wait=True)
try:
if args.action == 'replay':
try:
result = jobs.replay(args.attachment_id)
except (BotoCoreError, ClientError):
raise SystemExit('Источник для replay недоступен') from None
if result is None:
raise SystemExit('Нет подходящей failed-задачи')
print(json.dumps({'job_id': str(result[0]), 'attempt': result[1]}))
else:
with storage.pool.connection() as conn:
rows = conn.execute(
"""SELECT j.id, j.attachment_id, j.attempt, j.last_error, a.updated_at
FROM attachment_jobs j JOIN attachments a ON a.id=j.attachment_id
WHERE j.state='failed' ORDER BY a.updated_at DESC LIMIT 100"""
).fetchall()
print(json.dumps(rows, default=lambda value: str(value) if isinstance(value, UUID) else timestamp(value)))
finally:
storage.pool.close()
if __name__ == '__main__':
main()