PgFlow.WorkerOptions (PgFlow v0.7.2)

Copy Markdown View Source

Validation and resolution of per-worker max_concurrency and batch_size options, and of the :timeout option that worker check and scale calls accept.

Summary

Functions

Returns the default timeout, in milliseconds, for worker check and scale calls.

Returns the allowlisted worker option keys.

Removes and validates :timeout from opts, returning {timeout, rest}.

Resolves effective worker limits.

Splits worker options from other start options (for example :repo).

Validates worker option keywords.

Validates call options for check_worker and returns the call timeout.

Validates scale options; at least one of :max_concurrency or :batch_size is required.

Functions

default_call_timeout()

@spec default_call_timeout() :: pos_integer()

Returns the default timeout, in milliseconds, for worker check and scale calls.

keys()

@spec keys() :: [:max_concurrency | :batch_size]

Returns the allowlisted worker option keys.

pop_call_timeout!(opts)

@spec pop_call_timeout!(keyword()) :: {timeout(), keyword()}

Removes and validates :timeout from opts, returning {timeout, rest}.

The timeout defaults to 5000 milliseconds. Raises ArgumentError when it is not a non-negative integer or :infinity.

resolve(global, module, overrides)

@spec resolve(keyword(), module(), keyword()) :: %{
  max_concurrency: pos_integer(),
  batch_size: pos_integer()
}

Resolves effective worker limits.

Precedence: global config, then worker_options[module], then overrides. global must carry both keys, which PgFlow.Config.validate!/1 guarantees.

split(opts)

@spec split(keyword()) :: {keyword(), keyword()}

Splits worker options from other start options (for example :repo).

validate!(opts)

@spec validate!(keyword()) :: keyword()

Validates worker option keywords.

Raises ArgumentError on unknown keys or invalid values. An empty keyword list is valid.

validate_call!(opts)

@spec validate_call!(keyword()) :: timeout()

Validates call options for check_worker and returns the call timeout.

Accepts only :timeout (milliseconds or :infinity, default 5000). Raises ArgumentError on unknown keys or invalid values.

validate_scale!(opts)

@spec validate_scale!(keyword()) :: keyword()

Validates scale options; at least one of :max_concurrency or :batch_size is required.