Реализовать версии pipeline, fencing и автоматические сценарии отказов

This commit is contained in:
2026-11-20 06:51:54 +03:00
parent e376ede0a2
commit 42bf6aa702
21 changed files with 845 additions and 53 deletions
+14 -10
View File
@@ -12,27 +12,31 @@ from src.storage import storage, timestamp
def main():
parser = argparse.ArgumentParser()
parser.add_argument('action', choices=('failed', 'replay'))
parser.add_argument('action', choices=('failed', 'replay', 'upgrade'))
parser.add_argument('attachment_id', type=UUID, nargs='?')
parser.add_argument('--version', type=int, default=2)
args = parser.parse_args()
if args.action == 'replay' and args.attachment_id is None:
parser.error('replay requires attachment_id')
if args.action in ('replay', 'upgrade') and args.attachment_id is None:
parser.error('operation requires attachment_id')
storage.pool.open(wait=True)
try:
if args.action == 'replay':
if args.action in ('replay', 'upgrade'):
try:
result = jobs.replay(args.attachment_id)
if args.action == 'replay':
result = jobs.replay(args.attachment_id)
else:
job_id = jobs.upgrade(args.attachment_id, args.version)
result = (job_id, 1) if job_id else None
except (BotoCoreError, ClientError):
raise SystemExit('Источник для replay недоступен') from None
raise SystemExit('Источник обработки недоступен') from None
if result is None:
raise SystemExit('Нет подходящей failed-задачи')
raise SystemExit('Операция неприменима к текущему состоянию или версии')
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"""
"""SELECT id, attachment_id, pipeline_version, attempt, last_error, settled_at
FROM attachment_jobs WHERE state='failed' ORDER BY settled_at DESC NULLS LAST LIMIT 100"""
).fetchall()
print(json.dumps(rows, default=lambda value: str(value) if isinstance(value, UUID) else timestamp(value)))
finally: