feat(worker): prepare replay queries and audit schema

This commit is contained in:
kk10
2026-11-16 16:18:54 +03:00
parent 97b43a9c98
commit f2000a7883
7 changed files with 239 additions and 10 deletions
+33
View File
@@ -77,6 +77,13 @@ ORDER BY message_id, position;
SELECT id, s3_key, staging_key, status, size_bytes, updated_at
FROM attachments;
-- name: ListFailedAttachments :many
SELECT id, job_id, error_code, attempts, updated_at
FROM attachments
WHERE status = 'failed'
ORDER BY updated_at, id
LIMIT sqlc.arg(batch_size)::int;
-- name: LockAttachmentJob :one
SELECT * FROM attachments
WHERE id = sqlc.arg(id)::uuid
@@ -95,6 +102,17 @@ ORDER BY lease_until, id
LIMIT sqlc.arg(batch_size)::int
FOR UPDATE SKIP LOCKED;
-- name: LockFailedAttachmentForReplay :one
SELECT * FROM attachments
WHERE id = sqlc.arg(id)::uuid
AND status = 'failed'
AND staging_key IS NOT NULL
AND NOT EXISTS (
SELECT 1 FROM attachment_variants
WHERE attachment_id = attachments.id
)
FOR UPDATE;
-- name: ClearAttachmentStagingKey :exec
UPDATE attachments
SET staging_key = NULL
@@ -142,6 +160,21 @@ WHERE id = sqlc.arg(id)::uuid
AND attempts = sqlc.arg(attempt)::int
AND lease_until > now();
-- name: ReplayAttachmentJob :execrows
UPDATE attachments
SET status = 'queued',
retry_base = attempts,
error_code = NULL,
lease_until = NULL,
updated_at = now()
WHERE id = sqlc.arg(id)::uuid
AND status = 'failed'
AND staging_key IS NOT NULL
AND NOT EXISTS (
SELECT 1 FROM attachment_variants
WHERE attachment_id = attachments.id
);
-- name: FailAttachmentJob :execrows
UPDATE attachments
SET status = 'failed',