sorentwo/oban

Oban - Partitioning by worker and args at the same time does not work

Closed this issue · 2 comments

Environment

  • Oban Version : Pro 1.3.1
  • PostgreSQL Version: PostgreSQL 15.3 (Debian 15.3-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
  • Elixir & Erlang/OTP Versions (elixir --version): Elixir 1.15.7 (compiled with Erlang/OTP 26)

Current Behavior

When defining a queue partition limit as per the doc: https://hexdocs.pm/oban/2.11.0/smart_engine.html#partitioned-rate-limiting
global_limit: [allowed: 1, partition: [:worker, :args]]
or
global_limit: [allowed: 1, partition: [fields: [:worker, :args]]]

it fails pattern matching:

** (CaseClauseError) no case clause matching: %Oban.Pro.Producer.Meta.GlobalLimit.Partition{fields: ["args", "worker"], keys: []}
    (oban_pro 1.3.1) lib/oban/pro/engines/smart.ex:867: Oban.Pro.Engines.Smart.partition_by_fields/1

Which makes sense as the that code is:

  defp partition_by_fields(partition) do
    case partition do
      %{fields: ["worker"]} ->
        [:worker]

      %{fields: ["args"], keys: []} ->
        [:args]

      %{fields: ["args"], keys: keys} ->
        for key <- keys, do: dynamic([j], fragment("?->>?", j.args, ^key))
    end
  end

Adding a dbg there, the partition is:

partition #=> %Oban.Pro.Producer.Meta.GlobalLimit.Partition{
  fields: ["args", "worker"],
  keys: []
}

Expected Behavior

We should be able to partition by worker and args at the same time as per the doc.

This was fixed in Pro v1.4.0 🙂

Thanks! Sorry for not spotting that before raising the issue. 🙇