Class: Siding::Client
- Inherits:
-
Object
- Object
- Siding::Client
- Defined in:
- lib/siding/client.rb
Constant Summary collapse
- ACTIVE_ENVIRONMENTS =
%w[development test].freeze
- DISABLE_OFF_VALUES =
["0", "false", "no", "off", ""].freeze
- DEFAULT_BOOT_TIMEOUT =
90.0- NOTICE_AFTER =
0.75- FORWARDED_SIGNALS =
%w[INT TERM QUIT TSTP WINCH].freeze
- SUSPEND =
"TSTP"- SIGNAL_LINES =
FORWARDED_SIGNALS.to_h { |name| [name, "#{name}\n".freeze] }.freeze
- RESTART =
:restart- MAX_HANDOVERS =
3
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#cwd ⇒ Object
readonly
Returns the value of attribute cwd.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
- #app_env ⇒ Object
- #app_root ⇒ Object
- #decline_reason ⇒ Object
-
#initialize(argv, env: ENV, cwd: Dir.pwd) ⇒ Client
constructor
A new instance of Client.
- #project_key ⇒ Object
- #run ⇒ Object
- #runtime ⇒ Object
- #unusable_reason ⇒ Object
- #warm_up ⇒ Object
Constructor Details
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
24 25 26 |
# File 'lib/siding/client.rb', line 24 def argv @argv end |
#cwd ⇒ Object (readonly)
Returns the value of attribute cwd.
24 25 26 |
# File 'lib/siding/client.rb', line 24 def cwd @cwd end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
24 25 26 |
# File 'lib/siding/client.rb', line 24 def env @env end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
24 25 26 |
# File 'lib/siding/client.rb', line 24 def logger @logger end |
Class Method Details
.discover_app_root(start) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/siding/client.rb', line 59 def self.discover_app_root(start) dir = File.(start) loop do return dir if File.file?(File.join(dir, "config", "application.rb")) parent = File.dirname(dir) return nil if parent == dir dir = parent end end |
Instance Method Details
#app_env ⇒ Object
79 |
# File 'lib/siding/client.rb', line 79 def app_env = ProjectKey.app_env_from(env) |
#app_root ⇒ Object
53 54 55 56 57 |
# File 'lib/siding/client.rb', line 53 def app_root return @app_root if defined?(@app_root) @app_root = self.class.discover_app_root(cwd) end |
#decline_reason ⇒ Object
108 109 110 111 112 |
# File 'lib/siding/client.rb', line 108 def decline_reason return "#{argv.first} is not in the accelerated set" unless CLI.accelerated?(argv) unusable_reason end |
#project_key ⇒ Object
71 72 73 |
# File 'lib/siding/client.rb', line 71 def project_key @project_key ||= app_root && ProjectKey.for(app_root, env:) end |
#run ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/siding/client.rb', line 33 def run return CLI.new(argv, self).run if CLI.management?(argv.first) || argv.empty? reason = decline_reason if reason logger.debug("running unaccelerated: #{reason}") return passthrough end accelerated_run rescue Protocol::VersionMismatch => e logger.debug(e.) replace_mismatched_server rescue StandardError => e logger.debug("running unaccelerated after #{e.class}: #{e.}") passthrough ensure logger.close end |
#runtime ⇒ Object
75 76 77 |
# File 'lib/siding/client.rb', line 75 def runtime @runtime ||= project_key && Runtime.for(project_key, env:) end |
#unusable_reason ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/siding/client.rb', line 114 def unusable_reason return "SIDING_DISABLE is set" if disabled? return Platform.unsupported_reason unless Platform.supported? return "no Rails application found above #{cwd}" if app_root.nil? return "#{app_env.inspect} is not an accelerated environment" unless ACTIVE_ENVIRONMENTS.include?(app_env) runtime.unavailable_reason end |
#warm_up ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/siding/client.rb', line 81 def warm_up reason = unusable_reason if reason logger.debug("not warming up: #{reason}") return false end runtime.prepare # The connection attempt under the boot lock is the only authoritative answer to "was one # already warm?", so the distinction is carried out from there rather than reconstructed by # the caller from a record that can go stale between the two reads. outcome, socket = with_boot_lock do connected = try_connect next [:already_warm, connected] if connected runtime.discard_socket [:booted, boot_server] end return false if socket.nil? socket.close outcome rescue StandardError => e logger.debug("could not warm up: #{e.class}: #{e.}") false end |