Sha256: 2229946c819d3926f2ed9ca0b5a0b6c29ae8302e8ae5eddafac7eb2245778e11
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
require "optparse" module Racecar module Cli def self.main(args) parser = OptionParser.new do |opts| opts.banner = "Usage: racecar MyConsumer [options]" opts.on("-r", "--require LIBRARY", "Require the LIBRARY before starting the consumer") do |lib| require lib end opts.on_tail("--version", "Show Racecar version") do require "racecar/version" puts "Racecar #{Racecar::VERSION}" exit end end parser.parse!(args) consumer_name = args.first or raise Racecar::Error, "no consumer specified" config_file = "config/racecar.yml" puts "=> Starting Racecar consumer #{consumer_name}..." begin require "rails" puts "=> Detected Rails, booting application..." require "./config/environment" Racecar.config.load_file(config_file, Rails.env) if Racecar.config.log_to_stdout # Write to STDOUT as well as to the log file. console = ActiveSupport::Logger.new($stdout) console.formatter = Rails.logger.formatter console.level = Rails.logger.level Rails.logger.extend(ActiveSupport::Logger.broadcast(console)) end Racecar.logger = Rails.logger rescue LoadError # Not a Rails application. end # Find the consumer class by name. consumer_class = Kernel.const_get(consumer_name) # Load config defined by the consumer class itself. Racecar.config.load_consumer_class(consumer_class) Racecar.config.validate! puts "=> Wrooooom!" puts "=> Ctrl-C to shutdown consumer" processor = consumer_class.new Racecar.run(processor) puts "=> Shut down" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
racecar-0.1.4 | lib/racecar/cli.rb |