Class: BBQueue::Producer

Inherits:
Object
  • Object
show all
Defined in:
lib/bbqueue/producer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue_name, options = {}) ⇒ Producer

Returns a new instance of Producer.



6
7
8
9
10
# File 'lib/bbqueue/producer.rb', line 6

def initialize(queue_name, options = {})
  self.queue_name = queue_name
  self.logger = options[:logger] || BBQueue::NullLogger.new
  self.stalking = Stalking::Producer.new(options.merge(:logger => BBQueue::FatalLogger.new(logger)))
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



4
5
6
# File 'lib/bbqueue/producer.rb', line 4

def logger
  @logger
end

#queue_nameObject

Returns the value of attribute queue_name.



4
5
6
# File 'lib/bbqueue/producer.rb', line 4

def queue_name
  @queue_name
end

#stalkingObject

Returns the value of attribute stalking.



4
5
6
# File 'lib/bbqueue/producer.rb', line 4

def stalking
  @stalking
end

Instance Method Details

#enqueue(object, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bbqueue/producer.rb', line 12

def enqueue(object, options = {})
  logger.info "Enqueue #{object.inspect} with #{options.inspect} on #{queue_name.inspect}"

  obj = BBQueue::Serializer.dump(object)

  unless stalking.enqueue(queue_name, { "object" => obj }, options)
    logger.error "Enqueue #{obj.inspect} with #{options.inspect} on #{queue_name.inspect} failed"

    return false
  end

  true
end