Class: Qtrix::Matrix::RowBuilder

Inherits:
Object
  • Object
show all
Includes:
Common, Namespacing
Defined in:
lib/qtrix/matrix/row_builder.rb

Overview

Carries out the construction of rows within the matrix for a number of workers for a specific hostname.

Constant Summary

Constants included from Common

Common::REDIS_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

included, #pack, #unpack

Methods included from Namespacing

#extract_args, included, #redis, #redis_namespace

Constructor Details

#initialize(*args) ⇒ RowBuilder

Returns a new instance of RowBuilder.



15
16
17
18
19
20
21
# File 'lib/qtrix/matrix/row_builder.rb', line 15

def initialize(*args)
  @namespace, @hostname, @workers = extract_args(2, *args)
  @matrix = Qtrix::Matrix.fetch(namespace)
  @desired_distribution = Qtrix.desired_distribution(namespace)
  @heads = matrix.map{|row| row.entries.first.queue}
  @all_entries = matrix.map(&:entries).flatten
end

Instance Attribute Details

#all_entriesObject (readonly)

Returns the value of attribute all_entries.



12
13
14
# File 'lib/qtrix/matrix/row_builder.rb', line 12

def all_entries
  @all_entries
end

#desired_distributionObject (readonly)

Returns the value of attribute desired_distribution.



12
13
14
# File 'lib/qtrix/matrix/row_builder.rb', line 12

def desired_distribution
  @desired_distribution
end

#headsObject (readonly)

Returns the value of attribute heads.



12
13
14
# File 'lib/qtrix/matrix/row_builder.rb', line 12

def heads
  @heads
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



12
13
14
# File 'lib/qtrix/matrix/row_builder.rb', line 12

def hostname
  @hostname
end

#matrixObject (readonly)

Returns the value of attribute matrix.



12
13
14
# File 'lib/qtrix/matrix/row_builder.rb', line 12

def matrix
  @matrix
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



12
13
14
# File 'lib/qtrix/matrix/row_builder.rb', line 12

def namespace
  @namespace
end

#workersObject (readonly)

Returns the value of attribute workers.



12
13
14
# File 'lib/qtrix/matrix/row_builder.rb', line 12

def workers
  @workers
end

Instance Method Details

#buildObject



23
24
25
26
27
28
29
30
31
# File 'lib/qtrix/matrix/row_builder.rb', line 23

def build
  [].tap do |result|
    (1..workers).each do
      queues_for_row = queue_prioritizer.current_priority_queue
      build_row_for! hostname, queues_for_row
      result << queues_for_row.map(&:name)
    end
  end
end