Module: Reqless::JobReservers::Strategies::Filtering

Defined in:
lib/reqless/job_reservers/strategies/filtering.rb

Class Method Summary collapse

Class Method Details

.default(queues, regexes, queue_identifier_patterns, queue_priority_patterns) ⇒ Object

Return an enumerator of the filtered queues in in prioritized order.

Parameters:

  • queues (Enumerable)
    • a source of queues

  • regexes (Array)
    • a list of regexes to match against.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/reqless/job_reservers/strategies/filtering.rb', line 15

def self.default(
  queues,
  regexes,
  queue_identifier_patterns,
  queue_priority_patterns
)
  Enumerator.new do |yielder|
    # Map queues to their names
    mapped_queues = queues.reduce({}) do |hash,queue|
      hash[queue.name] = queue
      hash
    end

    # Filter the queue names against the regexes provided.
    matches = Reqless::QueuePatternsHelper.expand_queues(regexes, mapped_queues.keys, queue_identifier_patterns)

    # Prioritize the queues.
    prioritized_names = Reqless::QueuePatternsHelper.prioritize_queues(queue_priority_patterns, matches)

    prioritized_names.each do |name|
      queue = mapped_queues[name]
      if queue
        yielder << queue
      end
    end
  end
end