module Balance

Built-in backend selection policies.

Nested Classes and Modules

class Spread

Prefer the backend with the fewest active requests.

class Pack

Prefer a backend which is already processing the same class of work.

Definitions

def self.coerce(policy, **options)

Resolve a built-in policy name or validate an application policy object.

Signature

parameter policy Symbol | #select

The policy name or object.

parameter options Hash

Options for a built-in policy.

returns #select

The resolved balance policy.

Implementation

def self.coerce(policy, **options)
	case policy
	when :spread
		Spread.new(**options)
	when :pack
		Pack.new(**options)
	else
		unless policy.respond_to?(:select)
			raise ArgumentError, "Balance policy must respond to #select!"
		end
		
		policy
	end
end