Class: Racecar::Cli

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Cli

Returns a new instance of Cli.



18
19
20
21
22
23
# File 'lib/racecar/cli.rb', line 18

def initialize(args)
  @parser = build_parser
  @parser.parse!(args)
  @consumer_name = args.first or raise Racecar::Error, "no consumer specified"
  @runner = nil
end

Class Method Details

.main(args) ⇒ Object



13
14
15
# File 'lib/racecar/cli.rb', line 13

def main(args)
  new(args).run
end

Instance Method Details

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/racecar/cli.rb', line 25

def run
  $stderr.puts "=> Starting Racecar consumer #{consumer_name}..."

  RailsConfigFileLoader.load! unless config.without_rails?

  if File.exist?("config/racecar.rb")
    require "./config/racecar"
  end

  # Find the consumer class by name.
  consumer_class = Kernel.const_get(consumer_name)

  # Load config defined by the consumer class itself.
  config.load_consumer_class(consumer_class)

  config.validate!

  if config.logfile
    $stderr.puts "=> Logging to #{config.logfile}"
    Racecar.logger = Logger.new(config.logfile)
  end

  if config.log_level
    Racecar.logger.level = Object.const_get("Logger::#{config.log_level.upcase}")
  end

  if config.datadog_enabled
    configure_datadog
  end

  $stderr.puts "=> Wrooooom!"

  if config.daemonize
    daemonize!
  else
    $stderr.puts "=> Ctrl-C to shutdown consumer"
  end

  if config.liveness_probe_enabled
    $stderr.puts "=> Liveness probe enabled"
    config.install_liveness_probe
  end

  processor = consumer_class.new
  @runner = Racecar.runner(processor)
  @runner.run
  nil
end

#stopObject



74
75
76
# File 'lib/racecar/cli.rb', line 74

def stop
  @runner.stop
end