oban-bg / oban

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

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

Closed mathieurousseau closed 7 months ago

mathieurousseau commented 7 months ago

Environment

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.

sorentwo commented 7 months ago

This was fixed in Pro v1.4.0 🙂

mathieurousseau commented 7 months ago

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