agentsclimarketplace

Oban

Skill oliver-kriska/claude-elixir-phoenix/targets/pi/skills/oban

Oban job processing — workers, perform/1 (OSS) and process/1 (Pro), queues, cron, retries, unique jobs, idempotency, Oban Pro (Workflow, Batch, Chunk, Smart Engine), Testing. Use when writing Oban workers, queue config, or debugging jobs.From its SKILL.md

Install
npx -y skills add oliver-kriska/claude-elixir-phoenix --skill oban

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

3.9 KB, ~1.1k tokens by cl100k_base, as published. Nobody here has run it

Oban Background Jobs Reference

Quick reference for Elixir Oban patterns.

Oban Pro Detection

Before applying patterns, check for Oban Pro:

grep -E "oban_pro|oban_web" mix.exs
grep -r "use Oban.Pro.Worker" lib/
grep -r "Oban.Pro.Engines.Smart" config/

If Oban Pro detected, use Pro patterns for ALL new workers:

Standard ObanOban Pro
use Oban.Workeruse Oban.Pro.Worker
def perform(%Job{})def process(%Job{})
Oban.TestingOban.Pro.Testing
Advisory lock engineOban.Pro.Engines.Smart

Pro features (all optional): args_schema (typed args), Workflows, Batches, Chunks, Relay, hooks, encryption, deadlines, chaining, Smart Engine (global concurrency + rate limiting). Pro plugins (DynamicCron, DynamicLifeline, DynamicPruner) enhance OSS equivalents — swap module, don't run both. See references/oban-pro-basics.md for all patterns and migration guide.


Iron Laws — Never Violate These

  1. JOBS MUST BE IDEMPOTENT — Safe to retry. Use idempotency keys for payments
  2. JOBS MUST STORE IDs, NOT STRUCTS — JSON serialization. %{user_id: 1} not %{user: %User{}}
  3. JOBS MUST HANDLE ALL RETURN VALUES — :ok, {:error, _}, {:cancel, _}, {:snooze, _}
  4. ARGS USE STRING KEYS — Pattern match %{"user_id" => id} not %{user_id: id}
  5. UNIQUE CONSTRAINTS FOR USER ACTIONS — Prevent double-click duplicates
  6. NEVER STORE LARGE DATA IN ARGS — Store references (IDs, paths), not content
  7. SMART ENGINE: NEVER USE attempt TO LIMIT SNOOZES — Snooze rolls back attempt counter. Use meta["snoozed"] instead. Causes infinite loops

Quick Worker Template

defmodule MyApp.Workers.ExampleWorker do
  use Oban.Worker,
    queue: :default,
    max_attempts: 5,
    unique: [period: {5, :minutes}, keys: [:entity_id]]

  @impl Oban.Worker
  def perform(%Oban.Job{args: %{"entity_id" => id}}) do
    case process(id) do
      {:ok, _} -> :ok
      {:error, :not_found} -> {:cancel, "Entity not found"}
      {:error, :rate_limited} -> {:snooze, {5, :minutes}}
      {:error, reason} -> {:error, reason}
    end
  end
end

Return Value Meanings

ReturnStateBehavior
:okcompletedSuccess
{:ok, value}completedSuccess with value
{:error, reason}retryableRetry with backoff
{:cancel, reason}cancelledStop permanently
{:snooze, seconds}scheduledDelay and retry

Quick Decisions

Which Queue?

  • Critical operations → High concurrency (20+)
  • Mailers/Webhooks (I/O) → Medium concurrency (30-50)
  • CPU-intensive → Low concurrency (3-5)
  • External APIs → Use dispatch_cooldown for rate limiting

Testing Pattern

use Oban.Testing, repo: MyApp.Repo

# Assert enqueued
assert_enqueued worker: MyApp.Worker, args: %{id: 1}

# Execute and verify
assert :ok = perform_job(MyApp.Worker, %{id: 1})

Common Anti-patterns

WrongRight
%{user_id: id} pattern match%{"user_id" => id} (string keys)
%{user: %User{}} in args%{user_id: 1} (IDs only)
No idempotency for paymentsUse idempotency keys
Ignoring return valuesHandle all outcomes explicitly

References

For detailed patterns, see:

  • references/worker-patterns.md - Worker options, backoff, timeout
  • references/queue-config.md - Queue design, pool sizing, cron, Smart Engine
  • references/testing-patterns.md - Testing, assertions, drain (OSS + Pro)
  • references/oban-pro-basics.md - Pro.Worker, Workflow, Batch, Chunk, Relay, plugins

What ships with it: 4 files

18.3 KB alongside SKILL.md

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.