Class: Turnstile::Collector::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/turnstile/collector/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Runner

Returns a new instance of Runner.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/turnstile/collector/runner.rb', line 11

def initialize(*args)
  @config = args.last.is_a?(Hash) ? args.pop : {}
  @file   = config[:file]
  @queue  = Queue.new

  config[:debug] ? Turnstile::Logger.enable : Turnstile::Logger.disable

  wait_for_file(@file)

  self.reader
  self.updater

  Daemonize.daemonize if config[:daemonize]
  STDOUT.sync = true if config[:debug]
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



9
10
11
# File 'lib/turnstile/collector/runner.rb', line 9

def config
  @config
end

#fileObject

Returns the value of attribute file.



9
10
11
# File 'lib/turnstile/collector/runner.rb', line 9

def file
  @file
end

#queueObject

Returns the value of attribute queue.



9
10
11
# File 'lib/turnstile/collector/runner.rb', line 9

def queue
  @queue
end

#readerObject

Returns the value of attribute reader.



9
10
11
# File 'lib/turnstile/collector/runner.rb', line 9

def reader
  @reader
end

#updaterObject

Returns the value of attribute updater.



9
10
11
# File 'lib/turnstile/collector/runner.rb', line 9

def updater
  @updater
end

Instance Method Details

#log_reader_classObject



49
50
51
# File 'lib/turnstile/collector/runner.rb', line 49

def log_reader_class
  Turnstile::Collector::LogReader
end

#runObject



38
39
40
41
# File 'lib/turnstile/collector/runner.rb', line 38

def run
  threads = [reader, updater].map(&:run)
  threads.last.join
end

#wait_for_file(file) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/turnstile/collector/runner.rb', line 27

def wait_for_file(file)
  sleep_period = 1
  while !File.exist?(file)
    STDERR.puts "File #{file.bold.yellow} does not exist, waiting for it to appear..."
    STDERR.puts 'Press Ctrl-C to abort.' if sleep_period == 1

    sleep sleep_period
    sleep_period *= 1.2
  end
end