forked from mtusi2026/mtusi2026lab5
feat(attachments): add pipeline and outbox schema and queries
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
-- name: CreateOutboxEntry :one
|
||||
INSERT INTO outbox (
|
||||
job_id,
|
||||
attachment_id,
|
||||
pipeline_version,
|
||||
attempt,
|
||||
available_at
|
||||
)
|
||||
SELECT
|
||||
job_id,
|
||||
id,
|
||||
pipeline_version,
|
||||
sqlc.arg(attempt)::int,
|
||||
sqlc.arg(available_at)::timestamptz
|
||||
FROM attachments
|
||||
WHERE id = sqlc.arg(attachment_id)::uuid
|
||||
AND job_id IS NOT NULL
|
||||
RETURNING *;
|
||||
|
||||
-- name: LockPendingOutboxEntries :many
|
||||
SELECT * FROM outbox
|
||||
WHERE published_at IS NULL
|
||||
AND available_at <= now()
|
||||
ORDER BY available_at, id
|
||||
LIMIT sqlc.arg(batch_size)::int
|
||||
FOR UPDATE SKIP LOCKED;
|
||||
|
||||
-- name: MarkOutboxPublished :execrows
|
||||
UPDATE outbox
|
||||
SET published_at = now()
|
||||
WHERE id = sqlc.arg(id)::bigint
|
||||
AND published_at IS NULL;
|
||||
Reference in New Issue
Block a user