Class: Coordinator::Queue
- Inherits:
-
Object
- Object
- Coordinator::Queue
- Defined in:
- lib/coordinator/queue.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#skill ⇒ Object
readonly
Returns the value of attribute skill.
Instance Method Summary collapse
- #add_priority_task(task) ⇒ Object
- #add_task(task) ⇒ Object
- #capacity ⇒ Object
- #eligible?(task, skills) ⇒ Boolean
-
#initialize(skill, capacity = nil, &block) ⇒ Queue
constructor
A new instance of Queue.
- #items ⇒ Object
- #length ⇒ Object
- #next_task(skills) ⇒ Object
- #remove_task(task) ⇒ Object
- #set_capacity(capacity) ⇒ Object
Constructor Details
#initialize(skill, capacity = nil, &block) ⇒ Queue
Returns a new instance of Queue.
5 6 7 8 9 10 |
# File 'lib/coordinator/queue.rb', line 5 def initialize(skill, capacity=nil, &block) @skill = skill @store = Coordinator::RedisQueue.new(@skill) @store.capacity = capacity if capacity @custom_block = block if block_given? end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
3 4 5 |
# File 'lib/coordinator/queue.rb', line 3 def rules @rules end |
#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
#add_priority_task(task) ⇒ Object
16 17 18 |
# File 'lib/coordinator/queue.rb', line 16 def add_priority_task(task) @store.left_push(task) end |
#add_task(task) ⇒ Object
12 13 14 |
# File 'lib/coordinator/queue.rb', line 12 def add_task(task) @store.push(task) end |
#capacity ⇒ Object
44 45 46 |
# File 'lib/coordinator/queue.rb', line 44 def capacity @store.capacity end |
#eligible?(task, skills) ⇒ Boolean
31 32 33 34 |
# File 'lib/coordinator/queue.rb', line 31 def eligible?(task, skills) return true if skills.include?(@skill) @custom_block ? @custom_block.call(task, skills) : false end |
#items ⇒ Object
40 41 42 |
# File 'lib/coordinator/queue.rb', line 40 def items @store.items end |
#length ⇒ Object
48 49 50 |
# File 'lib/coordinator/queue.rb', line 48 def length @store.length end |
#next_task(skills) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/coordinator/queue.rb', line 24 def next_task(skills) task = @store.peek return nil unless task && eligible?(task, skills) return task if @store.remove(task) next_task(skills) end |
#remove_task(task) ⇒ Object
20 21 22 |
# File 'lib/coordinator/queue.rb', line 20 def remove_task(task) @store.remove(task) end |
#set_capacity(capacity) ⇒ Object
36 37 38 |
# File 'lib/coordinator/queue.rb', line 36 def set_capacity(capacity) @store.capacity = capacity end |