Class: FacebookService::QueuedLogMessageHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/extras/queued_log_message_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHandler

#aliveSince, #getCounter, #getCounters, #getCpuProfile, #getName, #getOption, #getOptions, #getStatus, #getStatusDetails, #getVersion, #reinitialize, #setOption, #shutdown

Constructor Details

#initialize(name, opts = {}) ⇒ QueuedLogMessageHandler

Returns a new instance of QueuedLogMessageHandler.



12
13
14
15
16
# File 'lib/extras/queued_log_message_handler.rb', line 12

def initialize(name, opts = {})
  super(name)

  @queue = opts[:queue] || Queue.new
end

Instance Attribute Details

#message_limitObject

If message_limit is exceeded, the handler will not accept any more messages from Scribe. The messages will be kept by Scribe and sent later.



10
11
12
# File 'lib/extras/queued_log_message_handler.rb', line 10

def message_limit
  @message_limit
end

#queueObject (readonly)

Returns the value of attribute queue.



5
6
7
# File 'lib/extras/queued_log_message_handler.rb', line 5

def queue
  @queue
end

Instance Method Details

#Log(messages) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/extras/queued_log_message_handler.rb', line 18

def Log(messages)
  if self.message_limit.nil? || (messages.length + self.queue.size) <= self.message_limit
    messages.each do |message|
      self.queue.push(message)
    end

    ::ResultCode::OK
  else
    ::ResultCode::TRY_LATER
  end
rescue Exception => e
  ::ResultCode::TRY_LATER
end