forked from mtusi2026/mtusi2026lab5
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
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()
|