Class: Raptor::CLI

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

Overview

Command-line interface for the Raptor web server.

CLI parses command-line arguments and starts the server cluster with the specified configuration options. It supports configuring the number of workers, threads, ractors, bind addresses, and various client timeout settings.

Examples:

Basic usage

cli = Raptor::CLI.new(["config.ru", "-t", "8", "-w", "4"])
cli.run

With custom timeouts

cli = Raptor::CLI.new(["--first-data-timeout", "60", "--threads", "8"])
cli.run

Constant Summary collapse

DEFAULT_WORKER_COUNT =
Etc.nprocessors
DEFAULT_OPTIONS =
{
  binds: ["tcp://0.0.0.0:9292"].freeze,
  threads: 3,
  ractors: 1,
  workers: DEFAULT_WORKER_COUNT,
  rackup: "config.ru",
  stats_file: "tmp/raptor.json",
  client: {
    first_data_timeout: 30,
    chunk_data_timeout: 10,
    persistent_data_timeout: 65,
  },
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ void

Creates a new CLI instance and parses command-line arguments.

Parses the provided command-line arguments and configures the server options accordingly. A rackup file can be provided as the first positional argument (defaults to config.ru).

Examples:

With rackup file

cli = CLI.new(["my_app.ru", "-w", "4"])

With options only

cli = CLI.new(["-t", "8", "-r", "2"])

Parameters:

  • argv (Array<String>)

    command-line arguments to parse

Raises:

  • (OptionParser::ParseError)

    if invalid options are provided



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/raptor/cli.rb', line 64

def initialize(argv)
  if argv.first == "stats"
    argv.shift
    @command = :stats
  else
    @command = :server
  end
  @options = DEFAULT_OPTIONS.dup
  @options[:client] = @options[:client].dup
  @parser = create_parser
  @parser.parse!(argv)

  @options[:rackup] = argv.first if @command == :server && argv.first
end

Instance Method Details

#runvoid

This method returns an undefined value.

Runs the requested command.



84
85
86
# File 'lib/raptor/cli.rb', line 84

def run
  @command == :stats ? run_stats : Cluster.run(@options)
end