perform_chunk does not properly set args for structured workers
SteffenDE opened this issue · 1 comments
SteffenDE commented
Similar to #649
Environment
- Oban Pro 1.0.2
Current Behavior
Trying to test a Chunk worker that is also structured using args_schema
does not properly populate the args, receiving string keys instead.
Pseudocode:
defmodule MyWorker do
use Oban.Pro.Workers.Chunk,
queue: :myqueue,
size: 25,
timeout: 1000,
by: [:worker, args: [:foo]]
args_schema do
field :foo, :string
field :bar, :string
end
@impl true
def process([_ | _] = jobs) do
foos = Enum.map(jobs, & &1.args.foo)
:ok
end
end
defmodule MyWorkerTest do
use ExUnit.Case, async: true
use Oban.Pro.Testing, repo: MyRepo
test "it works" do
assert {:ok, 2} = perform_chunk(MyWorker, [
%{
foo: "a",
bar: "1"
},
%{
foo: "b",
bar: "2"
}
])
end
end
Fails with an error like this:
** (KeyError) key :foo not found in: %{"foo" => "a", "bar" => "1"}
code: assert {:ok, 2} = perform_chunk(MyWorker, [
stacktrace:
(myapp 0.1.0) lib/myapp/myworker.ex:XY: anonymous fn/1 in MyWorker.process/1
(elixir 1.15.4) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
(myapp 0.1.0) lib/myapp/myworker.ex:XY: MyWorker.process/1
(oban_pro 1.0.2) lib/oban/pro/testing.ex:405: Oban.Pro.Testing.perform_chunk/3
test/my_worker_test.exs:59: (test)
Expected Behavior
Args should be structured as expected.
sorentwo commented
Thanks for the report. Fixed for the next patch release 👍