forked from mtusi2026/mtusi2026lab5
Исправить скачивание JPEG и добавить таймаут и DLQ
This commit is contained in:
@@ -15,7 +15,7 @@ def main():
|
||||
with psycopg.connect(database_url) as connection:
|
||||
with connection.transaction():
|
||||
row = connection.execute(
|
||||
"SELECT a.status, j.job_id FROM attachments a "
|
||||
"SELECT a.status, j.job_id, j.published_at FROM attachments a "
|
||||
"JOIN attachment_jobs j ON j.attachment_id=a.id "
|
||||
"WHERE a.id=%s FOR UPDATE",
|
||||
(args.attachment_id,),
|
||||
@@ -24,6 +24,8 @@ def main():
|
||||
raise SystemExit('attachment not found')
|
||||
if row[0] != 'failed':
|
||||
raise SystemExit('attachment is not failed')
|
||||
if row[2] is None:
|
||||
raise SystemExit('wait until the failure is published to the dead-letter stream')
|
||||
replay_id = uuid.uuid4()
|
||||
connection.execute(
|
||||
'INSERT INTO attachment_replays (replay_id,job_id) VALUES (%s,%s)',
|
||||
@@ -34,7 +36,8 @@ def main():
|
||||
(args.attachment_id,),
|
||||
)
|
||||
connection.execute(
|
||||
"UPDATE attachment_jobs SET attempt=1, published_at=NULL, next_attempt_at=now(), last_error=NULL WHERE job_id=%s",
|
||||
"UPDATE attachment_jobs SET attempt=1, published_at=NULL, next_attempt_at=now(), "
|
||||
"last_error=NULL, dead_letter_id=NULL WHERE job_id=%s",
|
||||
(row[1],),
|
||||
)
|
||||
print(json.dumps({'attachment_id': str(args.attachment_id), 'job_id': str(row[1]), 'replay_id': str(replay_id)}))
|
||||
|
||||
Reference in New Issue
Block a user