Skip to content

Commit

Permalink
use :poolboy.status to get free workers
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellhenke committed May 13, 2016
1 parent 140c26d commit 8e6e1aa
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/verk/workers_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ defmodule Verk.WorkersManager do
end

def handle_info(:timeout, state) do
workers = free_workers(state.monitors, state.pool_size)
workers = free_workers(state.pool_name)
if workers != 0 do
case QueueManager.dequeue(state.queue_manager_name, workers) do
jobs when is_list(jobs) ->
Expand Down Expand Up @@ -193,6 +193,8 @@ defmodule Verk.WorkersManager do
Log.start(job, worker)
Verk.Worker.perform_async(worker, self, job)
notify!(%Events.JobStarted{job: job, started_at: Timex.DateTime.now})
:full ->
Verk.enqueue(job)
end
end

Expand All @@ -217,8 +219,10 @@ defmodule Verk.WorkersManager do
:ok = GenEvent.ack_notify(Verk.EventManager, event)
end

defp free_workers(monitors, size) do
size - :ets.info(monitors, :size)
defp free_workers(pool_name) do
{_, free, _, _} = :poolboy.status(pool_name)

free
end

defp random_timeout(timeout) do
Expand Down

0 comments on commit 8e6e1aa

Please sign in to comment.