Class: Fairway::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/fairway/queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#connectionObject (readonly)

Returns the value of attribute connection.



3
4
5
# File 'lib/fairway/queue.rb', line 3

def connection
  @connection
end

#queue_namesObject (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



18
19
20
21
22
23
# File 'lib/fairway/queue.rb', line 18

def ==(other)
  other.respond_to?(:connection) &&
  other.respond_to?(:queue_names) &&
  connection == other.connection &&
  queue_names == other.queue_names
end

#lengthObject



10
11
12
# File 'lib/fairway/queue.rb', line 10

def length
  @connection.redis.mget(@queue_names.uniq.map{|q| "#{q}:length" }).sum.to_i
end

#pullObject



14
15
16
# File 'lib/fairway/queue.rb', line 14

def pull
  @connection.scripts.fairway_pull(@queue_names.shuffle.uniq)
end