ObanDoctor.Check.Worker.UniquenessMissingStates (oban_doctor v0.2.2)

Copy Markdown View Source

Checks for workers with unique configuration using explicit states that miss recommended ones.

When using explicit state lists (not named groups), you should typically include all non-final states: :available, :scheduled, :executing, and :retryable.

Why this matters: Missing :retryable is a common issue. When a job fails and enters the retryable state (with backoff), a new job with the same unique key can be enqueued, causing duplicates. This is especially problematic during deployments or pod scaling.

This check does NOT flag named state groups (:incomplete, :scheduled, :successful) as these are intentional Oban patterns.

How to fix

Add the missing states or use the :incomplete named group:

# Option 1: Add missing states
use Oban.Worker,
  queue: :default,
  unique: [fields: [:args], states: [:available, :scheduled, :executing, :retryable]]

# Option 2: Use :incomplete (recommended)
use Oban.Worker,
  queue: :default,
  unique: [fields: [:args], states: :incomplete]

See Oban unique jobs.

Configuration

In .oban_doctor.exs:

checks: [
  uniqueness_missing_states: [
    # Disable the check entirely
    enabled: false,

    # Or exclude specific workers from this check
    excluded_workers: [MyApp.Workers.LegacyWorker]
  ]
]