spring 4.5.0 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +25 -0
- data/lib/spring/application.rb +4 -0
- data/lib/spring/client/run.rb +39 -5
- data/lib/spring/configuration.rb +6 -0
- data/lib/spring/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a37d78748e084596d151cde2918d30799c8dfe9e10e029920ece9e9eee8118ad
|
|
4
|
+
data.tar.gz: c47e0897d3938b7350245854672812436505379cc498638c3eca9e2d52537fe6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cda176e1dd4d22cabb680cb85c4fd562c256f8fb3dc04f9064fc61f910cfb384f044f63bee74a424501505b62f80e0746f6c05bddf327c6be0150f12cc678a3f
|
|
7
|
+
data.tar.gz: e8b1675241b3fc42c52eabb9e2f501d4abae16c35ae3e3d19080de332f3d28b258b7245c127264326871f09c35c333a3b71fcfb8fbbfecdc87648a72e1328c14
|
data/README.md
CHANGED
|
@@ -79,6 +79,31 @@ Spring manages. That setting is typically configured in
|
|
|
79
79
|
Note: in versions of Rails before 7.1, the setting is called `cache_classes`,
|
|
80
80
|
and it needs to be `false` for Spring to work.
|
|
81
81
|
|
|
82
|
+
#### Running Spring with reloading disabled (advanced, risky)
|
|
83
|
+
|
|
84
|
+
If you know what you are doing, and if every reloadable resource is configured
|
|
85
|
+
to materialize *lazily in the forked child*, not in the Spring server process,
|
|
86
|
+
then you can decide to run Spring without Rail's in-process reloaders.
|
|
87
|
+
|
|
88
|
+
To opt into this, set in `config/spring.rb`:
|
|
89
|
+
|
|
90
|
+
```ruby
|
|
91
|
+
Spring.dangerously_allow_disabling_reloading = true
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
If you set this, you should make sure that you are NOT pre-loading reloadable
|
|
95
|
+
resource in the Spring server. One approach is to add boot-time assertions at
|
|
96
|
+
the end of `Spring.after_environment_load`, e.g.:
|
|
97
|
+
|
|
98
|
+
```ruby
|
|
99
|
+
Spring.after_environment_load do
|
|
100
|
+
raise "routes were drawn at boot" if Rails.application.routes_reloader.loaded
|
|
101
|
+
raise "i18n locales where loaded at boot" unless I18n.backend.instance_variable_get(:@translations).nil?
|
|
102
|
+
end
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
When unsure, leave this disabled.
|
|
106
|
+
|
|
82
107
|
### Usage
|
|
83
108
|
|
|
84
109
|
For this walkthrough I've generated a new Rails application, and run
|
data/lib/spring/application.rb
CHANGED
|
@@ -101,6 +101,8 @@ module Spring
|
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
Rails::Application.initializer :ensure_reloading_is_enabled, group: :all do
|
|
104
|
+
next if Spring.dangerously_allow_disabling_reloading
|
|
105
|
+
|
|
104
106
|
if Rails.application.config.cache_classes
|
|
105
107
|
config_name, set_to = if Rails.application.config.respond_to?(:enable_reloading=)
|
|
106
108
|
["enable_reloading", "true"]
|
|
@@ -110,6 +112,8 @@ module Spring
|
|
|
110
112
|
raise <<-MSG.strip_heredoc
|
|
111
113
|
Spring reloads, and therefore needs the application to have reloading enabled.
|
|
112
114
|
Please, set config.#{config_name} to #{set_to} in config/environments/#{Rails.env}.rb.
|
|
115
|
+
(If you understand the trade-offs and want to disable Rails' reloader anyway,
|
|
116
|
+
set `Spring.dangerously_allow_disabling_reloading = true` in config/spring.rb.)
|
|
113
117
|
MSG
|
|
114
118
|
end
|
|
115
119
|
end
|
data/lib/spring/client/run.rb
CHANGED
|
@@ -6,6 +6,7 @@ module Spring
|
|
|
6
6
|
module Client
|
|
7
7
|
class Run < Command
|
|
8
8
|
FORWARDED_SIGNALS = %w(INT QUIT USR1 USR2 INFO WINCH) & Signal.list.keys
|
|
9
|
+
ServerReadTimeout = Class.new(StandardError)
|
|
9
10
|
|
|
10
11
|
attr_reader :server
|
|
11
12
|
|
|
@@ -120,13 +121,27 @@ module Spring
|
|
|
120
121
|
end
|
|
121
122
|
|
|
122
123
|
def verify_server_version
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
begin
|
|
125
|
+
line = read_server_line
|
|
126
|
+
rescue ServerReadTimeout
|
|
127
|
+
if waiting_for_server_boot?
|
|
128
|
+
begin
|
|
129
|
+
# Try again, but with same timeout as booting, as server might still be booting
|
|
130
|
+
# from another client starting it.
|
|
131
|
+
line = read_server_line(Spring.boot_timeout)
|
|
132
|
+
rescue ServerReadTimeout
|
|
133
|
+
reboot_or_raise_connection_error
|
|
134
|
+
return
|
|
135
|
+
end
|
|
136
|
+
else
|
|
137
|
+
reboot_or_raise_connection_error
|
|
138
|
+
return
|
|
139
|
+
end
|
|
125
140
|
end
|
|
126
141
|
|
|
127
|
-
line
|
|
128
|
-
|
|
129
|
-
|
|
142
|
+
if line.nil?
|
|
143
|
+
reboot_or_raise_connection_error
|
|
144
|
+
return
|
|
130
145
|
end
|
|
131
146
|
|
|
132
147
|
server_version = line.chomp
|
|
@@ -145,6 +160,25 @@ module Spring
|
|
|
145
160
|
end
|
|
146
161
|
end
|
|
147
162
|
|
|
163
|
+
def read_server_line(timeout = Spring.connect_timeout)
|
|
164
|
+
raise ServerReadTimeout if IO.select([server], [], [], timeout).nil?
|
|
165
|
+
|
|
166
|
+
server.gets
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def waiting_for_server_boot?
|
|
170
|
+
!server_booted? && env.server_running?
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def reboot_or_raise_connection_error
|
|
174
|
+
if server_booted?
|
|
175
|
+
raise "Error connecting to Spring server"
|
|
176
|
+
else
|
|
177
|
+
stop_server
|
|
178
|
+
cold_run
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
148
182
|
def connect_to_application(client)
|
|
149
183
|
server.send_io client
|
|
150
184
|
send_json server, "args" => args, "default_rails_env" => default_rails_env, "spawn_env" => spawn_env, "reset_env" => reset_env
|
data/lib/spring/configuration.rb
CHANGED
|
@@ -3,11 +3,17 @@ require "spring/errors"
|
|
|
3
3
|
module Spring
|
|
4
4
|
@connect_timeout = 5
|
|
5
5
|
@boot_timeout = 20
|
|
6
|
+
@dangerously_allow_disabling_reloading = false
|
|
6
7
|
|
|
7
8
|
class << self
|
|
8
9
|
attr_accessor :application_root, :connect_timeout, :boot_timeout
|
|
9
10
|
attr_writer :quiet
|
|
10
11
|
|
|
12
|
+
# Opt-in: skip the `:ensure_reloading_is_enabled` initializer so Spring
|
|
13
|
+
# boots with `config.enable_reloading = false`. Default `false`. See
|
|
14
|
+
# README "Running Spring with reloading disabled" for what this gives up.
|
|
15
|
+
attr_accessor :dangerously_allow_disabling_reloading
|
|
16
|
+
|
|
11
17
|
def gemfile
|
|
12
18
|
require "bundler"
|
|
13
19
|
|
data/lib/spring/version.rb
CHANGED