aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/evented_file_update_checker.rb
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2016-06-06 15:24:56 -0500
committerschneems <richard.schneeman@gmail.com>2016-06-06 15:24:56 -0500
commita8f29f6455c303bbd321af248a730ca8b41f2f27 (patch)
treef79ec680745572bc8b7cbaa765e29ee53a6a63c1 /activesupport/lib/active_support/evented_file_update_checker.rb
parentbd38e92b41e055d107f4e4af8b60dfa6a38f444a (diff)
downloadrails-a8f29f6455c303bbd321af248a730ca8b41f2f27.tar.gz
rails-a8f29f6455c303bbd321af248a730ca8b41f2f27.tar.bz2
rails-a8f29f6455c303bbd321af248a730ca8b41f2f27.zip
Listen earlier in EventedFileUpdateChecker
Some files like routes.rb may be very large and vary between the initialization of the app and the first request. In these scenarios if we are using a forked process we cannot rely on the files to be unchanged between when the code is booted and the listener is started. For that reason we start a listener on the main process immediately, when we detect that a process does not have a listener started we force the updated state to be true, so we are guaranteed to catch any changes made between the code initialization and the fork.
Diffstat (limited to 'activesupport/lib/active_support/evented_file_update_checker.rb')
-rw-r--r--activesupport/lib/active_support/evented_file_update_checker.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/evented_file_update_checker.rb b/activesupport/lib/active_support/evented_file_update_checker.rb
index c0ad21b0df..063839f5af 100644
--- a/activesupport/lib/active_support/evented_file_update_checker.rb
+++ b/activesupport/lib/active_support/evented_file_update_checker.rb
@@ -13,8 +13,7 @@ module ActiveSupport
# EventedFileUpdateChecker#execute is run or when EventedFileUpdateChecker#execute_if_updated
# is run and there have been changes to the file system.
#
- # Note: To start listening to change events you must first call
- # EventedFileUpdateChecker#updated? inside of each process.
+ # Note: Forking will cause the first call to `updated?` to return `true`.
#
# Example:
#
@@ -41,10 +40,11 @@ module ActiveSupport
@dirs[@ph.xpath(dir)] = Array(exts).map { |ext| @ph.normalize_extension(ext) }
end
- @block = block
- @updated = Concurrent::AtomicBoolean.new(false)
- @lcsp = @ph.longest_common_subpath(@dirs.keys)
- @pid_hash = Concurrent::Hash.new
+ @block = block
+ @updated = Concurrent::AtomicBoolean.new(false)
+ @lcsp = @ph.longest_common_subpath(@dirs.keys)
+ @pid_hash = Concurrent::Hash.new
+ @parent_pid = Process.pid
if (@dtw = directories_to_watch).any?
# Loading listen triggers warnings. These are originated by a legit
@@ -58,6 +58,7 @@ module ActiveSupport
end
end
end
+ boot!
end
def updated?
@@ -82,6 +83,7 @@ module ActiveSupport
def boot!
Listen.to(*@dtw, &method(:changed)).start
@pid_hash[Process.pid] = true
+ @updated.make_true if @parent_pid != Process.pid
end
def changed(modified, added, removed)