fix(worker): lab5 enforce pipeline version check on claim
This commit is contained in:
@@ -195,15 +195,15 @@ func (r *AttachmentRepo) ExistingKeys(ctx context.Context, keys []string) ([]str
|
||||
return out, mapError(rows.Err())
|
||||
}
|
||||
|
||||
func (r *AttachmentRepo) ClaimForProcessing(ctx context.Context, id string, lease time.Duration) (*domain.Attachment, error) {
|
||||
func (r *AttachmentRepo) ClaimForProcessing(ctx context.Context, id string, version int, lease time.Duration) (*domain.Attachment, error) {
|
||||
const q = `
|
||||
UPDATE attachments
|
||||
SET status = 'processing', locked_until = now() + $2, updated_at = now(), attempts = attempts + 1 -- <--- ИНКРЕМЕНТ
|
||||
WHERE id = $1::uuid AND status = 'queued'
|
||||
SET status = 'processing', locked_until = now() + $2, updated_at = now(), attempts = attempts + 1
|
||||
WHERE id = $1::uuid AND status = 'queued' AND pipeline_version = $3
|
||||
RETURNING id, chat_id, staging_key, pipeline_version, object_key, content_type, attempts
|
||||
`
|
||||
var a domain.Attachment
|
||||
err := r.pool.QueryRow(ctx, q, id, lease).Scan(&a.ID, &a.ChatID, &a.StagingKey, &a.PipelineVersion, &a.ObjectKey, &a.ContentType, &a.Attempts)
|
||||
err := r.pool.QueryRow(ctx, q, id, lease, version).Scan(&a.ID, &a.ChatID, &a.StagingKey, &a.PipelineVersion, &a.ObjectKey, &a.ContentType, &a.Attempts)
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
return nil, nil
|
||||
|
||||
Reference in New Issue
Block a user