Skip to content

Commit

Permalink
Merge pull request #401 from akira/assert-concurrency-type
Browse files Browse the repository at this point in the history
cast queue level concurrency
  • Loading branch information
akira committed Jan 2, 2020
2 parents 0c2c650 + 465f779 commit 2c377b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/exq/support/opts.ex
Expand Up @@ -124,27 +124,27 @@ defmodule Exq.Support.Opts do
end

defp get_config_concurrency() do
case Config.get(:concurrency) do
x when is_atom(x) ->
x

x when is_integer(x) ->
x

x when is_binary(x) ->
case x |> String.trim() |> String.downcase() do
"infinity" -> :infinity
x -> Coercion.to_integer(x)
end
end
cast_concurrency(Config.get(:concurrency))
end

defp get_concurrency(queue_configs, per_queue_concurrency) do
Enum.map(queue_configs, fn queue_config ->
case queue_config do
{queue, concurrency} -> {queue, concurrency, 0}
{queue, concurrency} -> {queue, cast_concurrency(concurrency), 0}
queue -> {queue, per_queue_concurrency, 0}
end
end)
end

defp cast_concurrency(:infinity), do: :infinity
defp cast_concurrency(:infinite), do: :infinity
defp cast_concurrency(x) when is_integer(x), do: x

defp cast_concurrency(x) when is_binary(x) do
case x |> String.trim() |> String.downcase() do
"infinity" -> :infinity
"infinite" -> :infinity
x -> Coercion.to_integer(x)
end
end
end
12 changes: 12 additions & 0 deletions test/config_test.exs
Expand Up @@ -181,6 +181,18 @@ defmodule Exq.ConfigTest do

assert server_opts[:queues] == ["default", "test1"]
assert server_opts[:concurrency] == [{"default", 1000, 0}, {"test1", 2000, 0}]

Mix.Config.persist(
exq: [queues: [{"default", "1000"}, {"test1", "infinite"}, {"test2", "infinity"}]]
)

{Redix, [_redis_opts], server_opts} = Exq.Support.Opts.redis_worker_opts(mode: :default)

assert server_opts[:concurrency] == [
{"default", 1000, 0},
{"test1", :infinity, 0},
{"test2", :infinity, 0}
]
end

test "api redis_worker_opts" do
Expand Down

0 comments on commit 2c377b4

Please sign in to comment.