Class: Qtrix::Matrix::QueuePicker

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

Overview

Responsible for picking a number of queue lists from the matrix for a specific host. Will return already picked lists if they exist. Will generate new queue lists if they are needed and prune old lists as they are no longer needed, maintaining a row in the matrix for the number of workers for the host.

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) ⇒ QueuePicker

Returns a new instance of QueuePicker.



16
17
18
# File 'lib/qtrix/matrix/queue_picker.rb', line 16

def initialize(*args)
  @namespace, @reader, @hostname, @workers = extract_args(3, *args)
end

Instance Attribute Details

#hostnameObject (readonly)

Returns the value of attribute hostname.



14
15
16
# File 'lib/qtrix/matrix/queue_picker.rb', line 14

def hostname
  @hostname
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



14
15
16
# File 'lib/qtrix/matrix/queue_picker.rb', line 14

def namespace
  @namespace
end

#readerObject (readonly)

Returns the value of attribute reader.



14
15
16
# File 'lib/qtrix/matrix/queue_picker.rb', line 14

def reader
  @reader
end

#workersObject (readonly)

Returns the value of attribute workers.



14
15
16
# File 'lib/qtrix/matrix/queue_picker.rb', line 14

def workers
  @workers
end

Instance Method Details

#pick!Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/qtrix/matrix/queue_picker.rb', line 20

def pick!
  delta = workers - rows_for_host.size
  new_queues = []
  if delta > 0
    generate(delta)
  elsif delta < 0
    prune(delta)
  end
  rows_for_host.map(&to_queues)
end