Process attachment jobs through an outbox, a relay and a worker
Upload now stages the checked original under staging/, and one transaction moves the intent to queued, inserts the job (pipeline version 1, attempt 1), its outbox row and an audit event; the 202 is the in-memory snapshot, never a reread. Content answers 409 until the attachment is ready, the thumbnail variant is served from the published version and absent variants are 404. The relay publishes outbox rows through FastStream with publisher confirms, mandatory routing and persistent delivery, marks a row only after the broker acked it, returns jobs whose lease expired and deletes the staging object of ready attachments. The worker consumes the quorum queue through a FastStream subscriber that declares nothing, takes prefetch from WORKER_CONCURRENCY and acks manually after the result commit, rejects messages off jobs.schema.json to the dead letter exchange and requeues after an infrastructure error. A job is claimed under a lease token; the original is copied to originals/ and a 256 px JPEG thumbnail is written under a content-addressed key; the commit is fenced by the token, inserts variants with ON CONFLICT DO NOTHING and publishes only a newer pipeline version. A transient error reschedules the same job with an exponential delay and a new outbox row, the last attempt fails with retry_exhausted, an undecodable image fails at once with invalid_image, and a redelivered finished job is a recorded no-op. The worker and the relay are assembled in worker.py and relay.py with the dishka FastStream integration and the platform providers of the API; the shared core imports neither FastStream nor aio-pika. Tests cover the thumbnail geometry and rendering, the job message against the contract, the pipeline against PostgreSQL (duplicates, parallel copies, retries, the attempt bound, leases and fencing) and the broker adapters against a throwaway RabbitMQ with the stand's topology and permissions. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
64fdaa03f2
commit
b152b6e07e
@@ -5,25 +5,25 @@
|
||||
|
||||
## 2. Зона `attachments`: домен и приложение
|
||||
|
||||
- [ ] 2.1 Домен: статусы `queued/processing/failed`, `Attachment.enqueue`, `Variant`, геометрия `fit`, `Job` и его сообщение по `jobs.schema.json`, `Lease`, `RetryPolicy`, `FailureCode`, `Outcome`, события `AttachmentQueued`, `AttachmentReady`, `AttachmentFailed`, `JobRescheduled`, ошибка `AttachmentNotReady`
|
||||
- [ ] 2.2 Порты: `ObjectStorage.read`/`copy`, `VariantRenderer`, `JobPublisher`, `Faults`, репозитории `jobs` и `outbox` в `AttachmentsUnitOfWork`, `AttachmentDirectory.visible`
|
||||
- [ ] 2.3 Upload: `queued` вместо `ready`, задание и outbox в той же транзакции; запросы `GetAttachment`/`OpenAttachment` с `409` до `ready` и вариантами опубликованной версии
|
||||
- [ ] 2.4 Обработчики `ProcessJob` (захват, staging → оригинал, рендер, запись вариантов, фиксация с fencing, повтор/финальная ошибка), `PublishOutbox`, `RecoverExpiredLeases`, `CleanStaging`
|
||||
- [ ] 2.5 Проверка группы: unit-тесты `fit`, `RetryPolicy`, сообщения задания против `contracts/jobs.schema.json`
|
||||
- [x] 2.1 Домен: статусы `queued/processing/failed`, `Attachment.enqueue`, `Variant`, геометрия `fit`, `Job` и его сообщение по `jobs.schema.json`, `Lease`, `RetryPolicy`, `FailureCode`, `Outcome`, события `AttachmentQueued`, `AttachmentReady`, `AttachmentFailed`, `JobRescheduled`, ошибка `AttachmentNotReady`
|
||||
- [x] 2.2 Порты: `ObjectStorage.read`/`copy`, `VariantRenderer`, `JobPublisher`, `Faults`, репозитории `jobs` и `outbox` в `AttachmentsUnitOfWork`, `AttachmentDirectory.visible`
|
||||
- [x] 2.3 Upload: `queued` вместо `ready`, задание и outbox в той же транзакции; запросы `GetAttachment`/`OpenAttachment` с `409` до `ready` и вариантами опубликованной версии
|
||||
- [x] 2.4 Обработчики `ProcessJob` (захват, staging → оригинал, рендер, запись вариантов, фиксация с fencing, повтор/финальная ошибка), `PublishOutbox`, `RecoverExpiredLeases`, `CleanStaging`
|
||||
- [x] 2.5 Проверка группы: unit-тесты `fit`, `RetryPolicy`, сообщения задания против `contracts/jobs.schema.json`
|
||||
|
||||
## 3. Зона `attachments`: инфраструктура
|
||||
|
||||
- [ ] 3.1 PostgreSQL: вложение с ключами и вариантами, задания, outbox, события, захват аренды, фиксация с fencing и `published_version < v`, повтор, финальная ошибка, истёкшие аренды, staging к уборке
|
||||
- [ ] 3.2 S3: `read` и `copy`; Pillow: `PillowVariantRenderer` (EXIF orientation, 16 бит, alpha на белом, `fit`, JPEG без метаданных, классификация `invalid_image`)
|
||||
- [ ] 3.3 FastStream: адаптер `JobPublisher` (exchange без объявления, `persist`, `mandatory`, confirm, `message_id`), `FAULT_POINT` с точкой `transient_error`; зависимости `faststream[rabbit]`, `dishka-faststream` в `uv.lock`
|
||||
- [ ] 3.4 Проверка группы: тест рендера (fixture 320×200 → 256×160, RGBA на белом, EXIF 6, 17×1000 → 4×256, битые данные → `invalid_image`)
|
||||
- [x] 3.1 PostgreSQL: вложение с ключами и вариантами, задания, outbox, события, захват аренды, фиксация с fencing и `published_version < v`, повтор, финальная ошибка, истёкшие аренды, staging к уборке
|
||||
- [x] 3.2 S3: `read` и `copy`; Pillow: `PillowVariantRenderer` (EXIF orientation, 16 бит, alpha на белом, `fit`, JPEG без метаданных, классификация `invalid_image`)
|
||||
- [x] 3.3 FastStream: адаптер `JobPublisher` (exchange без объявления, `persist`, `mandatory`, confirm, `message_id`), `FAULT_POINT` с точкой `transient_error`; зависимости `faststream[rabbit]`, `dishka-faststream` в `uv.lock`
|
||||
- [x] 3.4 Проверка группы: тест рендера (fixture 320×200 → 256×160, RGBA на белом, EXIF 6, 17×1000 → 4×256, битые данные → `invalid_image`)
|
||||
|
||||
## 4. Точки входа и сборка процессов
|
||||
|
||||
- [ ] 4.1 HTTP: `202` upload, `variant` из четырёх значений, `409`, схема `AttachmentOut` со статусом и вариантами, реестр ошибок, журнал
|
||||
- [ ] 4.2 `PipelineSettings`, `PipelineProvider`, точка входа worker (FastStream-подписчик, проверка сообщения, `ack`/`reject`/`nack`), циклы relay, heartbeat
|
||||
- [ ] 4.3 Сборки `relay.py` и `worker.py`, тест графа импортов: сборки процессов знают одну зону, `shared/` не импортирует FastStream
|
||||
- [ ] 4.4 Проверка группы: тесты pipeline против одноразового PostgreSQL с памятью вместо S3 — `ready`, дубль после `ready` без новых строк, параллельные копии, временная ошибка → `queued` и новая строка outbox, исчерпание → `retry_exhausted`, `invalid_image` без повторов, fencing чужой аренды, возврат истёкшей аренды, уборка staging, публикация outbox
|
||||
- [x] 4.1 HTTP: `202` upload, `variant` из четырёх значений, `409`, схема `AttachmentOut` со статусом и вариантами, реестр ошибок, журнал
|
||||
- [x] 4.2 `PipelineSettings`, `PipelineProvider`, точка входа worker (FastStream-подписчик, проверка сообщения, `ack`/`reject`/`nack`), циклы relay, heartbeat
|
||||
- [x] 4.3 Сборки `relay.py` и `worker.py`, тест графа импортов: сборки процессов знают одну зону, `shared/` не импортирует FastStream
|
||||
- [x] 4.4 Проверка группы: тесты pipeline против одноразового PostgreSQL с памятью вместо S3 — `ready`, дубль после `ready` без новых строк, параллельные копии, временная ошибка → `queued` и новая строка outbox, исчерпание → `retry_exhausted`, `invalid_image` без повторов, fencing чужой аренды, возврат истёкшей аренды, уборка staging, публикация outbox
|
||||
|
||||
## 5. Связь зон
|
||||
|
||||
|
||||
Reference in New Issue
Block a user