Commit 28ad51bd authored by minibikini's avatar minibikini

update queues config

parent 5ecb0c28
...@@ -16,10 +16,10 @@ end ...@@ -16,10 +16,10 @@ end
## Configuration ## Configuration
You need to list your queues with max concurrent jobs like this: List your queues with max concurrent jobs like this:
```elixir ```elixir
config :pleroma_job_queue, config :pleroma_job_queue, :queues,
my_queue: 100, my_queue: 100,
another_queue: 50 another_queue: 50
``` ```
......
...@@ -20,10 +20,10 @@ defmodule PleromaJobQueue do ...@@ -20,10 +20,10 @@ defmodule PleromaJobQueue do
## Configuration ## Configuration
You need to list your queues with max concurrent jobs like this: List your queues with max concurrent jobs like this:
```elixir ```elixir
config :pleroma_job_queue, config :pleroma_job_queue, queues:
my_queue: 100, my_queue: 100,
another_queue: 50 another_queue: 50
``` ```
...@@ -76,8 +76,10 @@ defmodule PleromaJobQueue do ...@@ -76,8 +76,10 @@ defmodule PleromaJobQueue do
Returns a maximum concurrent jobs for a given queue name. Returns a maximum concurrent jobs for a given queue name.
""" """
@spec max_jobs(atom()) :: non_neg_integer() | nil @spec max_jobs(atom()) :: non_neg_integer()
def max_jobs(queue_name) do def max_jobs(queue_name) do
Application.get_env(:pleroma_job_queue, queue_name) :pleroma_job_queue
|> Application.get_env(:queues, [])
|> Keyword.get(queue_name, 1)
end end
end end
...@@ -20,8 +20,8 @@ defmodule PleromaJobQueue.Worker do ...@@ -20,8 +20,8 @@ defmodule PleromaJobQueue.Worker do
def init(%State{queues: queues} = state) do def init(%State{queues: queues} = state) do
queues = queues =
:pleroma_job_queue :pleroma_job_queue
|> Application.get_all_env() |> Application.get_env(:queues, [])
|> Enum.map(fn {name, _} -> {name, create_queue(name)} end) |> Enum.map(fn {name, _} -> {name, create_queue()} end)
|> Enum.into(%{}) |> Enum.into(%{})
|> Map.merge(queues) |> Map.merge(queues)
...@@ -30,7 +30,7 @@ defmodule PleromaJobQueue.Worker do ...@@ -30,7 +30,7 @@ defmodule PleromaJobQueue.Worker do
@impl true @impl true
def handle_cast({:enqueue, queue_name, mod, args, priority}, %State{queues: queues} = state) do def handle_cast({:enqueue, queue_name, mod, args, priority}, %State{queues: queues} = state) do
{running_jobs, queue} = Map.get(queues, queue_name, create_queue(queue_name)) {running_jobs, queue} = Map.get(queues, queue_name, create_queue())
queue = enqueue_sorted(queue, {mod, args}, priority) queue = enqueue_sorted(queue, {mod, args}, priority)
...@@ -76,9 +76,8 @@ defmodule PleromaJobQueue.Worker do ...@@ -76,9 +76,8 @@ defmodule PleromaJobQueue.Worker do
end end
end end
@spec create_queue(atom()) :: {State.running_jobs(), State.queue()} @spec create_queue() :: {State.running_jobs(), State.queue()}
def create_queue(queue_name) do def create_queue() do
unless max_jobs(queue_name), do: Application.put_env(:pleroma_job_queue, queue_name, 1)
{:sets.new(), []} {:sets.new(), []}
end end
......
...@@ -14,7 +14,7 @@ defmodule PleromaJobQueue.WorkerTest do ...@@ -14,7 +14,7 @@ defmodule PleromaJobQueue.WorkerTest do
setup do setup do
state = %State{ state = %State{
queues: Enum.into([Worker.create_queue(@queue_name)], %{}), queues: Enum.into([Worker.create_queue()], %{}),
refs: %{} refs: %{}
} }
...@@ -22,7 +22,7 @@ defmodule PleromaJobQueue.WorkerTest do ...@@ -22,7 +22,7 @@ defmodule PleromaJobQueue.WorkerTest do
end end
test "create_queue/1" do test "create_queue/1" do
{running_jobs, queue} = Worker.create_queue(:foobar) {running_jobs, queue} = Worker.create_queue()
assert queue == [] assert queue == []
assert :sets.is_set(running_jobs) assert :sets.is_set(running_jobs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment