Class: Disqualified::CLI

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/disqualified/cli.rb

Defined Under Namespace

Classes: ServerEngine

Constant Summary

Constants included from Logging

Logging::ERROR_CONTEXT_TYPE, Logging::ERROR_HOOK_TYPE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

format_log, handle_error

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



15
16
17
# File 'lib/disqualified/cli.rb', line 15

def initialize(argv)
  @original_argv = argv
end

Class Method Details

.runObject



4
5
6
7
# File 'lib/disqualified/cli.rb', line 4

def self.run
  cli = new(ARGV)
  cli.run
end

Instance Method Details

#runObject



19
20
21
22
23
24
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
# File 'lib/disqualified/cli.rb', line 19

def run
  require File.join(Dir.pwd, "config/environment")

  option_parser.parse(@original_argv)

  server_options = Disqualified.server_options
  delay_range = server_options.delay_range
  error_hooks = server_options.error_hooks
  logger = server_options.logger
  pool_size = server_options.pool_size

  # standard:disable Style/StringLiterals
  logger.info { '    ____  _                        ___ _____          __' }
  logger.info { '   / __ \(_)________ ___  ______ _/ (_) __(_)__  ____/ /' }
  logger.info { '  / / / / / ___/ __ `/ / / / __ `/ / / /_/ / _ \/ __  /' }
  logger.info { ' / /_/ / (__  ) /_/ / /_/ / /_/ / / / __/ /  __/ /_/ /' }
  logger.info { '/_____/_/____/\__, /\__,_/\__,_/_/_/_/ /_/\___/\__,_/' }
  logger.info { '                /_/' + "v#{Disqualified::VERSION}".rjust(32, " ") }
  # standard:enable Style/StringLiterals
  logger.info { Disqualified.server_options.to_s }

  pool = Disqualified::Pool.new(delay_range:, pool_size:, error_hooks:, logger:) do |args|
    args => {promise_index:}
    logger.debug { format_log("Disqualified::CLI#run <block>", "##{promise_index}") }
    Disqualified::Main.new(error_hooks:, logger:).call
  end
  pool.run!
rescue Interrupt
  pool&.shutdown
  puts
  puts "Gracefully quitting..."
end