lab5: очереди и асинхронная обработка изображений

Durable staging handoff, transactional outbox, at-least-once worker with lease fencing, idempotent versioned pipeline, three variants, operator tooling, contract tests and evidence. Includes the review fixes: reprocess source selection and failure settlement, replay guards, stale-job retirement, PNG structural/raster validation, migration rollback safety and audit events.
This commit is contained in:
Vladislav Kunetskiy
2026-10-31 14:34:24 +03:00
parent 6c5ba026f1
commit 01b885e846
99 changed files with 10164 additions and 1452 deletions
@@ -1,56 +1,3 @@
-- name: CreateAttachment :one
INSERT INTO attachments (
id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256, status
)
VALUES (
sqlc.arg(id),
sqlc.arg(chat_id),
sqlc.arg(owner_id),
sqlc.arg(object_key),
sqlc.arg(filename),
sqlc.arg(content_type),
sqlc.arg(size_bytes),
sqlc.arg(sha256),
'pending'
)
RETURNING id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256,
status, error_code, created_at, updated_at;
-- name: MarkAttachmentReady :one
UPDATE attachments
SET status = 'ready',
object_key = sqlc.arg(object_key),
updated_at = now()
WHERE id = sqlc.arg(id)
AND status = 'pending'
RETURNING id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256,
status, error_code, created_at, updated_at;
-- name: GetAttachmentForMember :one
SELECT a.id, a.chat_id, a.owner_id, a.object_key, a.filename, a.content_type,
a.size_bytes, a.sha256, a.status, a.error_code, a.created_at, a.updated_at
FROM attachments a
JOIN chat_members cm
ON cm.chat_id = a.chat_id
AND cm.user_id = sqlc.arg(user_id)
WHERE a.id = sqlc.arg(id);
-- name: GetAttachmentForOwner :one
SELECT a.id, a.chat_id, a.owner_id, a.object_key, a.filename, a.content_type,
a.size_bytes, a.sha256, a.status, a.error_code, a.created_at, a.updated_at
FROM attachments a
JOIN chat_members cm
ON cm.chat_id = a.chat_id
AND cm.user_id = a.owner_id
WHERE a.id = sqlc.arg(id)
AND a.owner_id = sqlc.arg(owner_id);
-- name: ListAttachmentStatesForChat :many
SELECT id, status
FROM attachments
WHERE chat_id = sqlc.arg(chat_id)
AND id = ANY(sqlc.arg(ids)::uuid[]);
-- name: AttachToMessage :exec
INSERT INTO message_attachments (message_id, attachment_id, position)
VALUES (sqlc.arg(message_id), sqlc.arg(attachment_id), sqlc.arg(position));
@@ -60,23 +7,3 @@ SELECT message_id, attachment_id
FROM message_attachments
WHERE message_id = ANY(sqlc.arg(message_ids)::uuid[])
ORDER BY message_id, position;
-- name: DeletePendingAttachment :exec
DELETE FROM attachments
WHERE id = sqlc.arg(id)
AND status = 'pending';
-- name: ListStalePendingAttachments :many
SELECT id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256,
status, error_code, created_at, updated_at
FROM attachments
WHERE status = 'pending'
AND created_at < sqlc.arg(created_before)
ORDER BY created_at
LIMIT sqlc.arg(row_limit);
-- name: ListAttachmentKeys :many
SELECT id, object_key, status, created_at
FROM attachments
ORDER BY id
LIMIT sqlc.arg(row_limit) OFFSET sqlc.arg(row_offset);