Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
joakimk committed Nov 1, 2015
1 parent b9e8b32 commit 930f35f
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions lib/toniq/job_concurrency_limiter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,10 @@ defmodule Toniq.JobConcurrencyLimiter do
)
end

defp below_max_concurrency?(state, job) do
running_count(state, job) < job.worker.max_concurrency
end

defp increase_running_count(state, job) do
update_running_count(state, job, +1)
end

defp decrease_running_count(state, job) do
update_running_count(state, job, -1)
end

# Running jobs count
defp below_max_concurrency?(state, job), do: running_count(state, job) < job.worker.max_concurrency
defp increase_running_count(state, job), do: update_running_count(state, job, +1)
defp decrease_running_count(state, job), do: update_running_count(state, job, -1)
defp update_running_count(state, job, difference) do
running_count = running_count(state, job) + difference

Expand All @@ -113,6 +105,7 @@ defmodule Toniq.JobConcurrencyLimiter do
state
end

# Worker state helpers
defp update_worker_state(state, job, worker_state), do: Map.put(state, job.worker, worker_state)
defp running_count(state, job), do: worker_state(state, job).running_count
defp pending_jobs(state, job), do: worker_state(state, job).pending_jobs
Expand Down

0 comments on commit 930f35f

Please sign in to comment.