- def handle_cast({:enqueue, type, payload}, {running_jobs, queue}) do
- queue = :queue.in({type, payload}, queue)
- {running_jobs, queue} = maybe_start_job(running_jobs, queue)
- {:noreply, {running_jobs, queue}}
+ def handle_cast({:enqueue, type, payload, priority}, state) when type in [:incoming_doc, :incoming_ap_doc] do
+ %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}} = state
+ i_queue = enqueue_sorted(i_queue, {type, payload}, 1)
+ {i_running_jobs, i_queue} = maybe_start_job(i_running_jobs, i_queue)
+ {:noreply, %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}}}
+ end
+
+ def handle_cast({:enqueue, type, payload, priority}, state) do
+ %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}} = state
+ o_queue = enqueue_sorted(o_queue, {type, payload}, 1)
+ {o_running_jobs, o_queue} = maybe_start_job(o_running_jobs, o_queue)
+ {:noreply, %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}}}