Class: Coordinator::Queue
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from RedisQueue
#capacity, #capacity=, #full?, #items, #left_push, #length, #peek, #pop, #push, #remove
Constructor Details
#initialize(skill, capacity = nil, &block) ⇒ Queue
5
6
7
8
9
10
11
|
# File 'lib/coordinator/queue.rb', line 5
def initialize(skill, capacity=nil, &block)
@skill = skill
self.capacity = capacity if capacity
@custom_block = block if block_given?
super(skill)
end
|
Instance Attribute Details
#skill ⇒ Object
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
28
29
30
31
32
33
34
35
36
|
# File 'lib/coordinator/queue.rb', line 28
def details
{
"name" => @skill,
"full" => full?,
"capacity" => capacity,
"count" => length,
"items" => items
}
end
|
#eligible?(task, skills) ⇒ Boolean
20
21
22
23
24
25
26
|
# File 'lib/coordinator/queue.rb', line 20
def eligible?(task, skills)
if @custom_block
self.instance_exec(task, skills, &@custom_block)
else
skills.include?(@skill)
end
end
|
#next_task(skills) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/coordinator/queue.rb', line 13
def next_task(skills)
task = peek
return nil unless task && eligible?(task, skills)
return task if remove(task)
next_task(skills)
end
|