Class: Dexter::Processor

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/dexter/processor.rb

Constant Summary

Constants included from Logging

Logging::COLOR_CODES

Instance Method Summary collapse

Methods included from Logging

#colorize, #log, #output

Constructor Details

#initialize(source, collector, indexer, interval:) ⇒ Processor

Returns a new instance of Processor.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dexter/processor.rb', line 5

def initialize(source, collector, indexer, interval:)
  @source = source
  @collector = collector
  @indexer = indexer

  @starting_interval = 3
  @interval = interval

  @mutex = Mutex.new
  @last_checked_at = {}

  log "Started" if !@source.is_a?(PgStatStatementsSource) && !@source.is_a?(StatementSource)
end

Instance Method Details

#performObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dexter/processor.rb', line 19

def perform
  if @source.is_a?(LogSource) && @source.stdin?
    Thread.abort_on_exception = true
    Thread.new do
      sleep(@starting_interval)
      loop do
        begin
          process_queries
        rescue PG::ServerError => e
          log colorize("ERROR: #{e.class.name}: #{e.message}", :red)
        end
        sleep(@interval)
      end
    end
  end

  begin
    @source.perform(@collector)
  rescue Errno::ENOENT => e
    raise Error, "ERROR: #{e.message}"
  end

  process_queries
end