forked from mtusi2026/mtusi2026lab5
feat(worker): add pipeline version upgrade command
This commit is contained in:
@@ -509,6 +509,43 @@ func (q *Queries) LockAttachmentByStagingKey(ctx context.Context, stagingKey str
|
||||
return i, err
|
||||
}
|
||||
|
||||
const lockAttachmentForUpgrade = `-- name: LockAttachmentForUpgrade :one
|
||||
SELECT id, chat_id, owner_id, s3_key, filename, content_type, size_bytes, sha256, status, error_code, created_at, updated_at, staging_key, job_id, pipeline_version, attempts, retry_base, width, height, lease_until FROM attachments
|
||||
WHERE id = $1::uuid
|
||||
AND pipeline_version = 1
|
||||
AND status IN ('queued', 'processing')
|
||||
AND staging_key IS NOT NULL
|
||||
FOR UPDATE
|
||||
`
|
||||
|
||||
func (q *Queries) LockAttachmentForUpgrade(ctx context.Context, id uuid.UUID) (Attachment, error) {
|
||||
row := q.db.QueryRow(ctx, lockAttachmentForUpgrade, id)
|
||||
var i Attachment
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ChatID,
|
||||
&i.OwnerID,
|
||||
&i.S3Key,
|
||||
&i.Filename,
|
||||
&i.ContentType,
|
||||
&i.SizeBytes,
|
||||
&i.Sha256,
|
||||
&i.Status,
|
||||
&i.ErrorCode,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.StagingKey,
|
||||
&i.JobID,
|
||||
&i.PipelineVersion,
|
||||
&i.Attempts,
|
||||
&i.RetryBase,
|
||||
&i.Width,
|
||||
&i.Height,
|
||||
&i.LeaseUntil,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const lockAttachmentJob = `-- name: LockAttachmentJob :one
|
||||
SELECT id, chat_id, owner_id, s3_key, filename, content_type, size_bytes, sha256, status, error_code, created_at, updated_at, staging_key, job_id, pipeline_version, attempts, retry_base, width, height, lease_until FROM attachments
|
||||
WHERE id = $1::uuid
|
||||
@@ -738,3 +775,25 @@ func (q *Queries) RetryAttachmentJob(ctx context.Context, arg RetryAttachmentJob
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const upgradeAttachmentPipeline = `-- name: UpgradeAttachmentPipeline :execrows
|
||||
UPDATE attachments
|
||||
SET pipeline_version = 2,
|
||||
status = 'queued',
|
||||
retry_base = attempts,
|
||||
error_code = NULL,
|
||||
lease_until = NULL,
|
||||
updated_at = now()
|
||||
WHERE id = $1::uuid
|
||||
AND pipeline_version = 1
|
||||
AND status IN ('queued', 'processing')
|
||||
AND staging_key IS NOT NULL
|
||||
`
|
||||
|
||||
func (q *Queries) UpgradeAttachmentPipeline(ctx context.Context, id uuid.UUID) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, upgradeAttachmentPipeline, id)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user