Class: Qtrix::Matrix::QueuePicker
- Inherits:
-
Object
- Object
- Qtrix::Matrix::QueuePicker
- 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
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
Instance Method Summary collapse
-
#initialize(*args) ⇒ QueuePicker
constructor
A new instance of QueuePicker.
- #pick! ⇒ Object
Methods included from Common
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
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
14 15 16 |
# File 'lib/qtrix/matrix/queue_picker.rb', line 14 def hostname @hostname end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
14 15 16 |
# File 'lib/qtrix/matrix/queue_picker.rb', line 14 def namespace @namespace end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
14 15 16 |
# File 'lib/qtrix/matrix/queue_picker.rb', line 14 def reader @reader end |
#workers ⇒ Object (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 |