GoodJob.Concurrency (good_job v1.0.0)

Copy Markdown View Source

Concurrency control for jobs.

Allows limiting the number of concurrent jobs per concurrency key, and throttling job enqueueing/execution.

Summary

Functions

Checks if a job can be enqueued based on concurrency limits.

Checks if a job can be performed based on concurrency limits.

Functions

check_enqueue_limit(concurrency_key, config)

Checks if a job can be enqueued based on concurrency limits.

Returns {:ok, :ok} if allowed.

If the limit or throttle is exceeded, or the advisory lock could not be taken, the result is {:ok, {:error, reason}} where reason is :limit_exceeded, :throttle_exceeded, or :lock_failed. That shape comes from Ecto.Repo.transaction/1 wrapping the callback return value (not a rolled-back transaction).

check_perform_limit(concurrency_key, job_id, config)

Checks if a job can be performed based on concurrency limits.

Returns {:ok, :ok} if allowed.

Otherwise returns {:ok, {:error, reason}} with reason in :limit_exceeded, :throttle_exceeded, or :lock_failed (see check_enqueue_limit/2 for why this is {:ok, {:error, _}}).