sorentwo / oban

💎 Robust job processing in Elixir, backed by modern PostgreSQL and SQLite3
https://getoban.pro
Apache License 2.0
3.17k stars 297 forks source link

Support `cancelled` callback in `Oban.Testing.Pro.perform_callback/4` #1089

Closed up2jj closed 1 month ago

up2jj commented 1 month ago

Environment

Current Behavior

I defined batch worker with the handle_cancelled/1 callback:

@impl Batch
def handle_cancelled(%Job{meta: %{"batch_id" => batch_id}}) do
  Logger.error("Some jobs were cancelled during import, batch_id: #{batch_id}")

  :ok
end

https://oban.dev/docs/pro/1.3.5/Oban.Pro.Workers.Batch.html#c:handle_cancelled/1

I am trying to test callback behaviour with Oban.Testing.Pro.perform_callback/4 but cancelled callback is not supported:

test "handle_cancelled/1" do
    assert :ok = perform_callback(MyJob, :cancelled, %{batch_id: "batch_id"})
end

It gives: Expected callback to be included in [:attempted, :completed, :discarded, :exhausted], got: :cancelled.

Checks for other callbacks work fine.

Expected Behavior

Oban.Testing.Pro.perform_callback/4 should support cancelled callback.

sorentwo commented 1 month ago

Thanks for the report. This is fixed on main and will be in the next patch release.