Class: Fairway::Facet
- Inherits:
-
Object
show all
- Defined in:
- lib/fairway/facet.rb
Defined Under Namespace
Classes: InvalidPriorityError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(queue, facet_name) ⇒ Facet
Returns a new instance of Facet.
7
8
9
10
|
# File 'lib/fairway/facet.rb', line 7
def initialize(queue, facet_name)
@queue = queue
@name = facet_name
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/fairway/facet.rb', line 5
def name
@name
end
|
#queue ⇒ Object
Returns the value of attribute queue.
5
6
7
|
# File 'lib/fairway/facet.rb', line 5
def queue
@queue
end
|
Instance Method Details
#==(other) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/fairway/facet.rb', line 40
def ==(other)
other.respond_to?(:queue) &&
other.respond_to?(:name) &&
queue == other.queue &&
name == other.name
end
|
#facet_key(queue) ⇒ Object
32
33
34
|
# File 'lib/fairway/facet.rb', line 32
def facet_key(queue)
"#{queue}:#{name}"
end
|
#length ⇒ Object
12
13
14
15
16
|
# File 'lib/fairway/facet.rb', line 12
def length
each_queue do |queue|
redis.llen(facet_key(queue))
end.sum
end
|
#priority ⇒ Object
18
19
20
21
22
|
# File 'lib/fairway/facet.rb', line 18
def priority
each_queue do |queue|
(redis.hget(priority_key(queue), name) || 1).to_i
end
end
|
#priority=(priority) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/fairway/facet.rb', line 24
def priority=(priority)
validate_priority!(priority)
each_queue do |queue|
scripts.fairway_priority(queue, name, priority)
end
end
|
#priority_key(queue) ⇒ Object
36
37
38
|
# File 'lib/fairway/facet.rb', line 36
def priority_key(queue)
"#{queue}:priorities"
end
|