elixir-phoenix-oban
Apply Oban patterns for workers, queues, retries, uniqueness, and testing.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Apply Oban patterns for workers, queues, retries, uniqueness, and testing.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Recommend the right `$elixir-phoenix-*` skill for the current task.
Elixir/Phoenix: Review lifecycle, state-machine, Oban, persistence, pause/resume, retry, and restart-sensitive changes before commit, push, or PR. Use for concurrency-sensitive runtime work to produce explicit blocking vs optional findings, require durability checks, and verify smoke plus restart resilience when applicable.
Capture a solved Phoenix problem as a reusable solution doc.
Audit LiveView assigns for memory bloat, dead assigns, and stream candidates.
Audit project health across architecture, security, performance, tests, and deps.
Analyze Phoenix context boundaries and coupling with `mix xref`.
| name | elixir-phoenix-oban |
| description | Apply Oban patterns for workers, queues, retries, uniqueness, and testing. |
| metadata | {"short-description":"Apply Oban job and queue patterns"} |
Quick reference for Elixir Oban patterns.
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 Oban | Oban Pro |
|---|---|
use Oban.Worker | use Oban.Pro.Worker |
def perform(%Job{}) | def process(%Job{}) |
Oban.Testing | Oban.Pro.Testing |
| Advisory lock engine | Oban.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 referenceselixir-phoenix-oban-pro-basics.md for all patterns and migration guide.
%{user_id: 1} not %{user: %User{}}:ok, {:error, _}, {:cancel, _}, {:snooze, _}%{"user_id" => id} not %{user_id: id}attempt TO LIMIT SNOOZES — Snooze rolls back attempt counter. Use meta["snoozed"] instead. Causes infinite loopsdefmodule 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 | State | Behavior |
|---|---|---|
:ok | completed | Success |
{:ok, value} | completed | Success with value |
{:error, reason} | retryable | Retry with backoff |
{:cancel, reason} | cancelled | Stop permanently |
{:snooze, seconds} | scheduled | Delay and retry |
dispatch_cooldown for rate limitinguse 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})
| Wrong | Right |
|---|---|
%{user_id: id} pattern match | %{"user_id" => id} (string keys) |
%{user: %User{}} in args | %{user_id: 1} (IDs only) |
| No idempotency for payments | Use idempotency keys |
| Ignoring return values | Handle all outcomes explicitly |
For detailed patterns, see:
references/worker-patterns.md - Worker options, backoff, timeoutreferences/queue-config.md - Queue design, pool sizing, cron, Smart Enginereferenceselixir-phoenix-testing-patterns.md - Testing, assertions, drain (OSS + Pro)referenceselixir-phoenix-oban-pro-basics.md - Pro.Worker, Workflow, Batch, Chunk, Relay, plugins