Class: AnyCable::CLI
- Inherits:
-
Object
- Object
- AnyCable::CLI
- Defined in:
- lib/anycable/cli.rb
Overview
Command-line interface for running AnyCable RPC server
Constant Summary collapse
- APP_CANDIDATES =
(not-so-big) List of common boot files for different applications
%w[ ./config/anycable.rb ./config/environment.rb ].freeze
- WAIT_PROCESS =
Wait for external process termination (s)
2
Instance Attribute Summary collapse
-
#embedded ⇒ Object
(also: #embedded?)
readonly
Returns the value of attribute embedded.
-
#health_server ⇒ Object
readonly
Returns the value of attribute health_server.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Class Method Summary collapse
-
.embed!(args = []) ⇒ Object
Run CLI inside the current process and shutdown at exit.
Instance Method Summary collapse
-
#initialize(embedded: false) ⇒ CLI
constructor
A new instance of CLI.
- #run(args = []) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(embedded: false) ⇒ CLI
Returns a new instance of CLI.
33 34 35 |
# File 'lib/anycable/cli.rb', line 33 def initialize(embedded: false) @embedded = end |
Instance Attribute Details
#embedded ⇒ Object (readonly) Also known as: embedded?
Returns the value of attribute embedded.
30 31 32 |
# File 'lib/anycable/cli.rb', line 30 def @embedded end |
#health_server ⇒ Object (readonly)
Returns the value of attribute health_server.
30 31 32 |
# File 'lib/anycable/cli.rb', line 30 def health_server @health_server end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
30 31 32 |
# File 'lib/anycable/cli.rb', line 30 def server @server end |
Class Method Details
.embed!(args = []) ⇒ Object
Run CLI inside the current process and shutdown at exit
23 24 25 26 27 28 |
# File 'lib/anycable/cli.rb', line 23 def self.(args = []) new(embedded: true).tap do |cli| cli.run(args) at_exit { cli.shutdown } end end |
Instance Method Details
#run(args = []) ⇒ Object
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/anycable/cli.rb', line 37 def run(args = []) @at_stop = [] = (args) # Boot app first, 'cause it might change # configuration, loggin settings, etc. boot_app! unless # Make sure Rails extensions for Anyway Config are loaded # See https://github.com/anycable/anycable-rails/issues/63 require "anyway/rails" if defined?(::Rails::VERSION) () configure_server! logger.info "Starting AnyCable RPC server (pid: #{Process.pid})" print_version! logger.info "Serving #{defined?(::Rails) ? "Rails " : ""}application from #{boot_file}" unless verify_connection_factory! log_errors! verify_server_builder! check_version! configure_middleware! @server = AnyCable.server_builder.call(config) # Make sure middlewares are not adding after server has started AnyCable.middleware.freeze start_health_server! if config.http_health_port_provided? start_pubsub! server.start run_custom_server_command! unless server_command.nil? return if begin wait_till_terminated rescue Interrupt => e logger.info "Stopping... #{e.}" shutdown logger.info "Stopped. Good-bye!" exit(0) end end |
#shutdown ⇒ Object
96 97 98 99 |
# File 'lib/anycable/cli.rb', line 96 def shutdown at_stop.each(&:call) server&.stop end |