Complete records the response for an OutcomeAcquired claim. After this point any subsequent Claim with the same key either replays (body matches) or 422s (body differs), until the row is swept. Idempotent against double-call: only updates rows still marked in_progress, so a stray re-Complete from a
(ctx context.Context, userID, key string, resp CachedResponse)
| 245 | // in_progress, so a stray re-Complete from a buggy caller cannot |
| 246 | // overwrite an already-cached response. |
| 247 | func (s *Store) Complete(ctx context.Context, userID, key string, resp CachedResponse) error { |
| 248 | _, err := s.pool.Exec(ctx, |
| 249 | `UPDATE idempotency_keys |
| 250 | SET status = 'completed', |
| 251 | response_status = $3, |
| 252 | response_content_type = $4, |
| 253 | response_body = $5, |
| 254 | completed_at = now() |
| 255 | WHERE user_id = $1 AND key = $2 AND status = 'in_progress'`, |
| 256 | userID, key, resp.StatusCode, resp.ContentType, resp.Body, |
| 257 | ) |
| 258 | return err |
| 259 | } |
| 260 | |
| 261 | // Release drops an OutcomeAcquired claim without recording a response. |
| 262 | // Use when the caller decided not to perform the side effect (e.g. |