lib/anycable/cli.rb in anycable-1.0.0.rc1 vs lib/anycable/cli.rb in anycable-1.0.0.rc2
- old
+ new
@@ -18,31 +18,36 @@
].freeze
# Wait for external process termination (s)
WAIT_PROCESS = 2
- attr_reader :server, :health_server
+ attr_reader :server, :health_server, :embedded
+ alias embedded? embedded
+ def initialize(embedded: false)
+ @embedded = embedded
+ end
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
- def run(args = {})
+ def run(args = [])
@at_stop = []
extra_options = parse_cli_options!(args)
# Boot app first, 'cause it might change
# configuration, loggin settings, etc.
- boot_app!
+ boot_app! unless embedded?
parse_gem_options!(extra_options)
configure_server!
logger.info "Starting AnyCable gRPC server (pid: #{Process.pid}, workers_num: #{config.rpc_pool_size})"
print_versions!
- logger.info "Serving #{defined?(::Rails) ? "Rails " : ""}application from #{boot_file}"
+ logger.info "Serving #{defined?(::Rails) ? "Rails " : ""}application from #{boot_file}" unless embedded?
verify_connection_factory!
log_grpc! if config.log_grpc
@@ -64,10 +69,12 @@
server.start
run_custom_server_command! unless server_command.nil?
+ return if embedded?
+
begin
wait_till_terminated
rescue Interrupt => e
logger.info "Stopping... #{e.message}"
@@ -79,10 +86,10 @@
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
def shutdown
at_stop.each(&:call)
- server.stop
+ server&.stop
end
private
attr_reader :boot_file, :server_command