class Pack

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

Definitions

def initialize(affinity: nil)

Signature

parameter affinity Symbol | Nil

The queue affinity to pack, or the current queue by default.

Implementation

def initialize(affinity: nil)
	@affinity = affinity
end

def select(backends, queue:, request:)

Select the backend with the most active work for the affinity.

Signature

parameter backends Array(Backend)

Eligible backends with available permits.

parameter queue Queue

The request queue being scheduled.

parameter request Protocol::HTTP::Request

The pending request.

returns Backend | Nil

The preferred backend.

Implementation

def select(backends, queue:, request:)
	affinity = @affinity || queue.name
	backends.min_by do |backend|
		[-backend.processing_for(affinity), backend.processing, backend.name]
	end
end