Class: FastlyNsq::CLI

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/fastly_nsq/cli.rb

Overview

Provides functionality to support running FastlyNsq as a command line application that listens and processes NSQ messages.

Examples:

begin
  cli = FastlyNsq::CLI.instance
  cli.parse_options
  cli.run
rescue => e
  raise e if $DEBUG
  STDERR.puts e.message
  STDERR.puts e.backtrace.join("\n")
  exit 1
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



29
30
31
# File 'lib/fastly_nsq/cli.rb', line 29

def options
  @options
end

Instance Method Details

#parse_options(args = ARGV) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/fastly_nsq/cli.rb', line 31

def parse_options(args = ARGV)
  parse(args)
  setup_logger
  check_pid
  daemonize if daemonize?
  write_pid
end

#runObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fastly_nsq/cli.rb', line 39

def run
  startup

  launcher.beat

  read_loop
rescue Interrupt
  FastlyNsq.logger.info "Shutting down"
  launcher.stop
  # Explicitly exit so busy Processor threads can't block
  # process shutdown.
  FastlyNsq.logger.info "Bye!"
  exit(0)
end