forked from mtusi2026/mtusi2026lab5
Добавить варианты изображений, очистку staging, replay и сценарии отказа
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user