Class: Coordinator::Queue
- Inherits:
-
RedisQueue
- Object
- RedisQueue
- Coordinator::Queue
- Defined in:
- lib/coordinator/queue.rb
Instance Attribute Summary collapse
-
#skill ⇒ Object
readonly
Returns the value of attribute skill.
Instance Method Summary collapse
- #details ⇒ Object
- #eligible?(task, skills) ⇒ Boolean
-
#initialize(skill, capacity = nil, &block) ⇒ Queue
constructor
A new instance of Queue.
- #next_task(skills) ⇒ Object
Methods inherited from RedisQueue
#capacity, #capacity=, #full?, #items, #left_push, #length, #peek, #pop, #push, #remove
Constructor Details
#initialize(skill, capacity = nil, &block) ⇒ Queue
Returns a new instance of Queue.
5 6 7 8 9 10 11 12 |
# File 'lib/coordinator/queue.rb', line 5 def initialize(skill, capacity=nil, &block) @skill = skill @custom_block = block if block_given? super(skill) self.capacity = capacity if capacity end |
Instance Attribute Details
#skill ⇒ Object (readonly)
Returns the value of attribute skill.
3 4 5 |
# File 'lib/coordinator/queue.rb', line 3 def skill @skill end |
Instance Method Details
#details ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/coordinator/queue.rb', line 29 def details { "name" => @skill, "full" => full?, "capacity" => capacity, "count" => length, "items" => items } end |
#eligible?(task, skills) ⇒ Boolean
21 22 23 24 25 26 27 |
# File 'lib/coordinator/queue.rb', line 21 def eligible?(task, skills) if @custom_block self.instance_exec(task, skills, &@custom_block) else skills.include?(@skill) end end |
#next_task(skills) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/coordinator/queue.rb', line 14 def next_task(skills) task = peek return nil unless task && eligible?(task, skills) return task if remove(task) next_task(skills) end |