class Pack
Prefer a backend which is already processing the same class of work.
Definitions
def initialize(affinity: nil)
Signature
-
parameter
affinitySymbol | 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
backendsArray(Backend) Eligible backends with available permits.
-
parameter
queueQueue The request queue being scheduled.
-
parameter
requestProtocol::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