Class: Remon::EventProcessor

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/remon/event_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

logger, #logger

Constructor Details

#initialize(pr) ⇒ EventProcessor

Returns a new instance of EventProcessor.



9
10
11
12
# File 'lib/remon/event_processor.rb', line 9

def initialize(pr)
  @proc = pr
  @queue = Queue.new
end

Instance Attribute Details

#queueObject (readonly)

Returns the value of attribute queue.



7
8
9
# File 'lib/remon/event_processor.rb', line 7

def queue
  @queue
end

Instance Method Details

#process_eventObject



21
22
23
24
25
26
# File 'lib/remon/event_processor.rb', line 21

def process_event
  event = @queue.pop
  @proc.call event
rescue => e
  logger.warn "warn error #{e.message}"
end

#startObject



14
15
16
17
18
19
# File 'lib/remon/event_processor.rb', line 14

def start
  @thread ||= Thread.new do
    logger.debug { "starting event processor" }
    loop { process_event }
  end
end

#stopObject



28
29
30
# File 'lib/remon/event_processor.rb', line 28

def stop
  Thread.kill @thread if @thread
end