Commit 28ad51bd authored by minibikini's avatar minibikini

update queues config

parent 5ecb0c28
......@@ -16,10 +16,10 @@ end
## Configuration
You need to list your queues with max concurrent jobs like this:
List your queues with max concurrent jobs like this:
```elixir
config :pleroma_job_queue,
config :pleroma_job_queue, :queues,
my_queue: 100,
another_queue: 50
```
......
......@@ -20,10 +20,10 @@ defmodule PleromaJobQueue do
## Configuration
You need to list your queues with max concurrent jobs like this:
List your queues with max concurrent jobs like this:
```elixir
config :pleroma_job_queue,
config :pleroma_job_queue, queues:
my_queue: 100,
another_queue: 50
```
......@@ -76,8 +76,10 @@ defmodule PleromaJobQueue do
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
Application.get_env(:pleroma_job_queue, queue_name)
:pleroma_job_queue
|> Application.get_env(:queues, [])
|> Keyword.get(queue_name, 1)
end
end
......@@ -20,8 +20,8 @@ defmodule PleromaJobQueue.Worker do
def init(%State{queues: queues} = state) do
queues =
:pleroma_job_queue
|> Application.get_all_env()
|> Enum.map(fn {name, _} -> {name, create_queue(name)} end)
|> Application.get_env(:queues, [])
|> Enum.map(fn {name, _} -> {name, create_queue()} end)
|> Enum.into(%{})
|> Map.merge(queues)
......@@ -30,7 +30,7 @@ defmodule PleromaJobQueue.Worker do
@impl true
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)
......@@ -76,9 +76,8 @@ defmodule PleromaJobQueue.Worker do
end
end
@spec create_queue(atom()) :: {State.running_jobs(), State.queue()}
def create_queue(queue_name) do
unless max_jobs(queue_name), do: Application.put_env(:pleroma_job_queue, queue_name, 1)
@spec create_queue() :: {State.running_jobs(), State.queue()}
def create_queue() do
{:sets.new(), []}
end
......
......@@ -14,7 +14,7 @@ defmodule PleromaJobQueue.WorkerTest do
setup do
state = %State{
queues: Enum.into([Worker.create_queue(@queue_name)], %{}),
queues: Enum.into([Worker.create_queue()], %{}),
refs: %{}
}
......@@ -22,7 +22,7 @@ defmodule PleromaJobQueue.WorkerTest do
end
test "create_queue/1" do
{running_jobs, queue} = Worker.create_queue(:foobar)
{running_jobs, queue} = Worker.create_queue()
assert queue == []
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