Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

193 Job claim locking and lease durations

  • Status: Accepted
  • Date: 2026-02-14
  • Context:
    • Motivation: close ERD job_schedule gaps for claim semantics and per-job lease durations.
    • Constraints: stored-procedure-only runtime DB access, constant error messages, migration-safe CREATE OR REPLACE updates.
  • Decision:
    • Add job_claim_lease_seconds_v1 (+ stable wrapper) as the single lease-duration mapping source for all job_key values.
    • Update job_claim_next_v1 to acquire advisory lock before reading job_schedule, then validate due/locked/enabled state and set locked_until using job_claim_lease_seconds_v1.
    • Alternatives considered: keep inline CASE mapping in job_claim_next_v1 (rejected: duplicated lease logic), and rely on pre-lock state checks only (rejected: race window for stale schedule reads).
  • Consequences:
    • Positive outcomes: claim flow now aligns with ERD advisory-lock + locked_until semantics and applies lease durations from one canonical mapping.
    • Risks or trade-offs: claim function now returns job_locked earlier when advisory lock contention exists, which may mask other validation details during concurrent claims.
  • Follow-up:
    • Keep new lease mapping synchronized if job_key enum values change.
    • Review checkpoint: verify scheduler/executor callers consume job_claim_next errors without re-logging.
  • Test coverage summary:
    • Added stored-proc integration tests for job_claim_next not-due and locked failures.
    • Added per-job lease-duration assertion test covering all seeded job_key values.
  • Observability updates:
    • None (DB procedure behavior + tests only).
  • Risk & rollback plan:
    • Roll back by reverting migration 0085_indexer_job_claim_locking.sql and restoring prior job_claim_next_v1 logic.
  • Dependency rationale:
    • No new dependencies. Alternatives considered: not applicable.