Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/spring/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ def preload

require Spring.application_root_path.join("config", "environment")

# Run user-supplied post-environment-load callbacks (e.g. preloading the
# test runtime so forked children skip 2+s of require chains).
Spring.after_environment_load_callbacks.each do |callback|
begin
callback.call
rescue Exception => err
log "after_environment_load callback raised: #{err.class}: #{err.message}"
raise
end
end

disconnect_database

@preloaded = :success
Expand Down
12 changes: 12 additions & 0 deletions lib/spring/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ def after_fork(&block)
after_fork_callbacks << block
end

# Callbacks invoked once on the spring server, after config/environment
# has finished loading and Rails autoloads are wired up. Use this to
# preload heavy test/dev support files that depend on Rails being ready,
# so the forked child doesn't pay the cost on every command.
def after_environment_load_callbacks
@after_environment_load_callbacks ||= []
end

def after_environment_load(&block)
after_environment_load_callbacks << block
end

def spawn_on_env
@spawn_on_env ||= []
end
Expand Down
Loading