Class: Fairway::Queue
- Inherits:
-
Object
- Object
- Fairway::Queue
- Defined in:
- lib/fairway/queue.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#queue_names ⇒ Object
readonly
Returns the value of attribute queue_names.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #active_facets ⇒ Object
- #destroy ⇒ Object
-
#initialize(connection, *queue_names) ⇒ Queue
constructor
A new instance of Queue.
- #length ⇒ Object
- #peek ⇒ Object
- #pull ⇒ Object
- #queue_key ⇒ Object
- #redis ⇒ Object
- #scripts ⇒ Object
- #unique_queues ⇒ Object
Constructor Details
#initialize(connection, *queue_names) ⇒ Queue
Returns a new instance of Queue.
5 6 7 8 |
# File 'lib/fairway/queue.rb', line 5 def initialize(connection, *queue_names) @connection = connection @queue_names = parse_queue_names(queue_names) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
3 4 5 |
# File 'lib/fairway/queue.rb', line 3 def connection @connection end |
#queue_names ⇒ Object (readonly)
Returns the value of attribute queue_names.
3 4 5 |
# File 'lib/fairway/queue.rb', line 3 def queue_names @queue_names end |
Instance Method Details
#==(other) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/fairway/queue.rb', line 32 def ==(other) other.respond_to?(:connection) && other.respond_to?(:queue_names) && connection == other.connection && queue_names == other.queue_names end |
#active_facets ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/fairway/queue.rb', line 10 def active_facets facet_names = unique_queues.map do |queue| redis.smembers("#{queue}:active_facets") end.flatten.uniq facet_names.map do |name| Facet.new(self, name) end end |
#destroy ⇒ Object
47 48 49 |
# File 'lib/fairway/queue.rb', line 47 def destroy scripts.fairway_destroy(unique_queues) end |
#length ⇒ Object
20 21 22 |
# File 'lib/fairway/queue.rb', line 20 def length redis.mget(unique_queues.map{|q| "#{q}:length" }).map(&:to_i).sum end |
#peek ⇒ Object
24 25 26 |
# File 'lib/fairway/queue.rb', line 24 def peek scripts.fairway_peek(@queue_names.shuffle.uniq) end |
#pull ⇒ Object
28 29 30 |
# File 'lib/fairway/queue.rb', line 28 def pull scripts.fairway_pull(@queue_names.shuffle.uniq) end |
#queue_key ⇒ Object
43 44 45 |
# File 'lib/fairway/queue.rb', line 43 def queue_key queue end |
#redis ⇒ Object
51 52 53 |
# File 'lib/fairway/queue.rb', line 51 def redis @connection.redis end |
#scripts ⇒ Object
55 56 57 |
# File 'lib/fairway/queue.rb', line 55 def scripts @connection.scripts end |
#unique_queues ⇒ Object
39 40 41 |
# File 'lib/fairway/queue.rb', line 39 def unique_queues @queue_names.uniq end |