Class: BarnyardLogger::Logs

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Logs

Returns a new instance of Logs.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/barnyard_logger.rb', line 14

def initialize(args)

  @debug = args.fetch(:debug) { false }
  @log = args.fetch(:logger) { Logger.new(STDOUT) }

  @cachecow_settings = args.fetch(:cachecow_settings) { raise "You must provide :cachecow_settings" }

  @cachecow = BarnyardCcfeeder::CacheCow.new(@cachecow_settings)

  @q = BarnyardHarvester::GenericQueue.new(args)

end

Instance Method Details

#process_changesObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/barnyard_logger.rb', line 51

def process_changes

  while (msg = @q.pop(BarnyardHarvester::QUEUE_CHANGE)) do

    payload = Crack::JSON.parse(msg)

    begin
      @cachecow.push_change(payload['queued_at'],
                            payload['harvester_uuid'],
                            payload['change_uuid'],
                            payload['crop_number'],
                            payload['primary_key'],
                            payload['transaction_type'],
                            payload['value'],
                            payload['old_value'])

    rescue Exception => e
      $stderr.puts e
    end

  end
end

#process_harvestsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/barnyard_logger.rb', line 27

def process_harvests

  while (msg = @q.pop(BarnyardHarvester::QUEUE_HARVESTER)) do

    payload = Crack::JSON.parse(msg)

    begin
      @cachecow.push_harvester_stats(payload['harvester_uuid'],
                                     payload['crop_number'],
                                     payload['began_at'],
                                     payload['ended_at'],
                                     payload['source_count'],
                                     payload['change_count'],
                                     payload['add_count'],
                                     payload['delete_count'])

    rescue Exception => e
      $stderr.puts e
    end

  end

end

#process_transactionsObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/barnyard_logger.rb', line 74

def process_transactions

  while (msg = @q.pop(BarnyardHarvester::QUEUE_TRANSACTION)) do

    payload = Crack::JSON.parse(msg)

    begin
      @cachecow.push_transaction(payload['subscription_id'],
                                 payload['queued_at'],
                                 payload['change_uuid'],
                                 payload['transaction_uuid'])

    rescue Exception => e
      $stderr.puts e
    end

  end

end