Commit 0075b533 authored by minibikini's avatar minibikini

add an option to disable async

parent e6789085
......@@ -23,11 +23,16 @@ defmodule PleromaJobQueue do
List your queues with max concurrent jobs like this:
```elixir
config :pleroma_job_queue, queues:
config :pleroma_job_queue, :queues,
my_queue: 100,
another_queue: 50
```
You can disable `pleroma_job_queue` if you need to your jobs synchronously:
```elixir
config :pleroma_job_queue, disabled: true
```
"""
@doc """
......@@ -67,9 +72,13 @@ defmodule PleromaJobQueue do
"""
@spec enqueue(atom(), module(), [any()], non_neg_integer()) :: :ok
@spec enqueue(atom(), module(), [any()], non_neg_integer()) :: any()
def enqueue(queue_name, mod, args \\ [], priority \\ 1) do
GenServer.cast(PleromaJobQueue.Worker, {:enqueue, queue_name, mod, args, priority})
if enabled?() do
GenServer.cast(PleromaJobQueue.Worker, {:enqueue, queue_name, mod, args, priority})
else
apply(mod, :perform, args)
end
end
@doc """
......@@ -82,4 +91,6 @@ defmodule PleromaJobQueue do
|> Application.get_env(:queues, [])
|> Keyword.get(queue_name, 1)
end
defp enabled?(), do: not Application.get_env(:pleroma_job_queue, :disabled, false)
end
......@@ -10,6 +10,7 @@ defmodule PleromaJobQueueTest do
def perform, do: send(pid(), {:test, :no_args})
def perform(:skip), do: nil
def perform(:sync), do: :sync
def perform(:test_job), do: send(pid(), :test_job)
def perform(:test_job, a, b), do: send(pid(), {:test_job, {a, b}})
def perform(:priority, priority), do: send(pid(), {:priority, priority})
......@@ -35,6 +36,12 @@ defmodule PleromaJobQueueTest do
PleromaJobQueue.max_jobs(@queue_name)
end
test "disable" do
Application.put_env(:pleroma_job_queue, :disabled, true)
assert :sync == PleromaJobQueue.enqueue(@queue_name, Worker, [:sync])
Application.put_env(:pleroma_job_queue, :disabled, false)
end
test "priority" do
set_pid()
......
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