lab5: асинхронная очередь, worker и идемпотентный pipeline
API принимает 202 после durable staging и TX intent (job+outbox); отдельные relay и worker публикуют/обрабатывают задания с publisher confirm, lease, retry/backoff, DLQ и replay. Добавлены версии pipeline, варианты thumbnail/crop/optimized, presign в verified staging, status-aware sweeper и admission control.
This commit is contained in:
@@ -52,10 +52,10 @@ def put(url, content, content_type='image/png'):
|
||||
return error.code
|
||||
|
||||
|
||||
def complete(client, actor, attachment_id, digest, expected=200):
|
||||
def complete(client, actor, attachment_id, digest, expected=202):
|
||||
return client.call(
|
||||
'POST', '/api/v1/attachments/' + attachment_id + '/complete', expected,
|
||||
actor=actor, body={'sha256': digest}, schema='Attachment' if expected == 200 else None,
|
||||
actor=actor, body={'sha256': digest}, schema='Attachment' if expected == 202 else None,
|
||||
)
|
||||
|
||||
|
||||
@@ -73,7 +73,8 @@ def main():
|
||||
check(put(presigned['upload_url'], content) == 200, 'direct PUT failed')
|
||||
attachment = complete(client, alice, presigned['attachment_id'], digest)['json']
|
||||
check(attachment['sha256'] == digest and attachment['size_bytes'] == len(content), 'completed metadata mismatch')
|
||||
print('happy path: direct PUT 200, complete ready, checksum/size match')
|
||||
attachment = client.wait_ready(alice, attachment)
|
||||
print('happy path: direct PUT 200, complete queued, ready after worker')
|
||||
|
||||
client.message(alice, chat, '', attachments=[attachment['id']])
|
||||
download = client.call('GET', '/api/v1/attachments/' + attachment['id'] + '/content', actor=bob)
|
||||
@@ -83,6 +84,7 @@ def main():
|
||||
# Completion is idempotent.
|
||||
again = complete(client, alice, presigned['attachment_id'], digest)['json']
|
||||
check(again['id'] == attachment['id'], 'repeated complete returned another attachment')
|
||||
check(again['status'] in ('queued', 'processing', 'ready'), 'repeated complete returned an invalid state')
|
||||
print('repeated complete is idempotent')
|
||||
|
||||
# A foreign user cannot complete someone else's pending upload.
|
||||
|
||||
Reference in New Issue
Block a user