рестеу бвт2302 лаба5

This commit is contained in:
Otto
2026-11-17 03:47:52 +03:00
parent 276dbdad8a
commit 8c36a874ce
26 changed files with 1680 additions and 48 deletions
+28
View File
@@ -0,0 +1,28 @@
import argparse
from uuid import UUID
from src.db import pool
def main():
parser = argparse.ArgumentParser()
parser.add_argument('attachment_id')
args = parser.parse_args()
identifier = UUID(args.attachment_id)
pool.open(wait=True)
with pool.connection() as conn:
with conn.transaction():
row = conn.execute('SELECT status,pipeline_version FROM attachments WHERE id=%s FOR UPDATE',
(identifier,)).fetchone()
if row is None or row['status'] != 'failed':
raise SystemExit('Только failed-вложение можно повторно отправить в обработку')
conn.execute('''UPDATE attachments SET status='queued',attempts=0,error_code=NULL,
lease_token=NULL,lease_until=NULL,next_attempt_at=now(),updated_at=now()
WHERE id=%s''', (identifier,))
conn.execute('INSERT INTO attachment_outbox(attachment_id,pipeline_version) VALUES (%s,%s)',
(identifier,row['pipeline_version']))
print('QUEUED:',identifier)
if __name__=='__main__':
main()