Class: Promiscuous::Subscriber::Worker::Recorder

Inherits:
Object
  • Object
show all
Defined in:
lib/promiscuous/subscriber/worker/recorder.rb

Instance Method Summary collapse

Constructor Details

#initialize(log_file) ⇒ Recorder

Returns a new instance of Recorder.



2
3
4
5
# File 'lib/promiscuous/subscriber/worker/recorder.rb', line 2

def initialize(log_file)
  @log_file = log_file
  extend Promiscuous::AMQP::Subscriber
end

Instance Method Details

#startObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/promiscuous/subscriber/worker/recorder.rb', line 7

def start
  @file = File.open(@log_file, 'a')
  options = {}
  options[:queue_name] = "#{Promiscuous::Config.app}.promiscuous"
  options[:bindings] = {}
  # We need to subscribe to everything to keep up with the version tracking
  Promiscuous::Config.subscriber_exchanges.each do |exchange|
    options[:bindings][exchange] = ['*']
  end

  subscribe(options) do |, payload|
    @file.puts payload
    .ack
  end
end

#stopObject



23
24
25
26
# File 'lib/promiscuous/subscriber/worker/recorder.rb', line 23

def stop
  disconnect
  @file.try(:close)
end