Jump.CredoChecks.UseObanProWorker (Jump.CredoChecks v0.7.1)

View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of high and works with any version of Elixir.

Explanation

Ensures that Oban worker modules use the Oban.Pro.Worker module instead of Oban.Worker.

If your project integrates Oban Pro at all, it's worth ensuring you always use the Pro worker so that you get all the Pro features.

# ❌ Bad (misses Pro features)
defmodule MyWorker do
  use Oban.Worker
end

# ✅ Good
defmodule MyWorker do
  use Oban.Pro.Worker
end

Additionally, when a worker declares an args_schema, Oban Pro casts the job's args into a struct with atom keys before calling process/1. Matching on string keys in the args will therefore never succeed.

# ❌ Bad (never matches; args have atom keys)
defmodule MyWorker do
  use Oban.Pro.Worker

  args_schema do
    field :service, :string, required: true
  end

  def process(%Oban.Job{args: %{"service" => service}}), do: ...
end

# ✅ Good
defmodule MyWorker do
  use Oban.Pro.Worker

  args_schema do
    field :service, :string, required: true
  end

  def process(%Oban.Job{args: %{service: service}}), do: ...
end

Check-Specific Parameters

Use the following parameters to configure this check:

:supported_worker_modules

Worker modules that are treated as equivalent to Oban.Pro.Worker. Defaults to [Oban.Pro.Worker]. Replace or extend the list if your project wraps Oban Pro in its own worker module(s).

Modules named in this list are excluded from the check entirely, so a project wrapper may itself use Oban.Pro.Worker (or use Oban.Worker) without being flagged.

use Oban.Worker is always flagged in other modules. use Oban.Pro.Worker is flagged when Oban.Pro.Worker is not in this list. The check for use of string keys in process/1 args applies to modules that use any entry in this list.

Example (allow Oban Pro and a project wrapper):

  {Jump.CredoChecks.UseObanProWorker,
   supported_worker_modules: [Oban.Pro.Worker, MyApp.Workers.Base]}

Example (only allow a project wrapper):

  {Jump.CredoChecks.UseObanProWorker,
   supported_worker_modules: [MyApp.Workers.Base]}

This parameter defaults to [Oban.Pro.Worker].

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.