Skip to content

Commit

Permalink
Skip reporter queries with empty states or queues
Browse files Browse the repository at this point in the history
Querying with an empty list may cause the following error:

```
(Postgrex.Error) ERROR 42809 (wrong_object_type) op ANY/ALL (array)
```

This fixes the erorr by skipping queries for empty lists. This could
happen if all of the states were above the estimate threshold, or no
active queues were found.

Closes oban-bg/oban#1182
  • Loading branch information
sorentwo committed Nov 14, 2024
1 parent ff89b69 commit 392fb8e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/oban/met/reporter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,19 @@ defmodule Oban.Met.Reporter do
end)
end

defp count_query(states) do
defp count_query([]), do: where(Job, [_], false)

defp count_query(states) when is_list(states) do
Job
|> select([j], %{series: :full_count, state: j.state, queue: j.queue, value: count(j.id)})
|> where([j], j.state in ^states)
|> group_by([j], [j.state, j.queue])
end

defp guess_query(states, queues, conf) do
defp guess_query([], _queues, _conf), do: where(Job, [_], false)
defp guess_query(_states, [], _conf), do: where(Job, [_], false)

defp guess_query(states, queues, conf) when is_list(states) and is_list(queues) do
from(p in fragment("json_array_elements_text(?)", ^queues),
cross_join: x in fragment("json_array_elements_text(?)", ^states),
select: %{
Expand Down

0 comments on commit 392fb8e

Please sign in to comment.