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

Copy Markdown View Source

Checks for workers using the :all state group in unique configuration.

Oban provides named state groups for unique constraints:

  • :successful (default) - excludes cancelled/discarded, safe for most cases
  • :incomplete - only unfinished jobs, good for preventing concurrent execution
  • :scheduled - only scheduled jobs, useful for debouncing
  • :all - includes cancelled and discarded jobs (DANGEROUS)

Using states: :all is dangerous because it includes :completed and :discarded states. This means once a job completes or is discarded, you can never enqueue another job with the same unique key.

How to fix

Replace :all with a named state group or explicit states:

# Use :incomplete to prevent concurrent execution
use Oban.Worker,
  queue: :default,
  unique: [fields: [:args], states: :incomplete]

# Or use explicit states
use Oban.Worker,
  queue: :default,
  unique: [fields: [:args], states: [:available, :scheduled, :executing, :retryable]]

See Oban unique jobs.

Configuration

In .oban_doctor.exs:

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

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