## Arguments
- `queue_name` - a queue name(must be specified in the config).
- - `mod` - a worker module, must have `perform` function.
+ - `mod` - a worker module (must have `perform` function).
- `args` - a list of arguments for the `perform` function of the worker module.
- `priority` - a job priority (`0` by default).
end
else
@spec enqueue(atom(), atom(), [any()], integer()) :: :ok
- def enqueue(queue_name, mod, args, priority \\ 1) do
+ def enqueue(queue_name, mod, args, priority) do
GenServer.cast(__MODULE__, {:enqueue, queue_name, mod, args, priority})
end
end
{:noreply, state}
end
- def handle_cast(m, state) do
- IO.inspect("Unknown: #{inspect(m)}, #{inspect(state)}")
- {:noreply, state}
- end
-
def handle_info({:DOWN, ref, :process, _pid, _reason}, state) do
queue_name = state.refs[ref]
running_jobs = :sets.del_element(ref, running_jobs)
- state = state |> remove_ref(ref) |> maybe_start_job(queue_name, running_jobs, queue)
+ state =
+ state
+ |> remove_ref(ref)
+ |> update_queue(queue_name, {running_jobs, queue})
+ |> maybe_start_job(queue_name, running_jobs, queue)
{:noreply, state}
end
|> add_ref(queue_name, mref)
|> update_queue(queue_name, {:sets.add_element(mref, running_jobs), queue})
else
- update_queue(state, queue_name, {running_jobs, queue})
+ state
end
end