Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reentrant calls to RakeCommand.perform #39137

Merged
merged 1 commit into from May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions railties/lib/rails/commands/rake/rake_command.rb
Expand Up @@ -15,12 +15,11 @@ def printing_commands
def perform(task, args, config)
require_rake

ARGV.replace([task, *args]) # set up ARGV for Rake

Rake.application.standard_exception_handling do
Rake.application.init("rails")
Rake.application.load_rakefile
Rake.application.top_level
Rake.with_application do |rake|
load "rails/tasks.rb"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate that this file has to be loaded each time, but I could not find a sanctioned way to copy loaded tasks from one instance to another. Neither Rake::Application nor Rake::TaskManager seem to have the necessary public accessors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will reloading throw any constant redefined or similar warnings? Is it tough on performance?

Not sure if we know someone involved with Rake we could tap to help fit an API for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was one constant redefined warning that I fixed: https://github.com/rails/rails/pull/39137/files#diff-94b3f444d3f09e55370aa7e94f440408R6

As for performance, I'm sure it is slower, but I didn't really notice the difference when I was repeatedly running tasks to try out the fix. And it should still beat shelling out and loading the entire Rails context in another process, which is what was happening before adding inline: true.

It would be cool if Rake supported this use case explicitly. Depending on how common this use case is, an option like Rake.with_application(preserve_tasks: true) would be pretty slick. Otherwise, something like Rake::Application#dup_without_top_level would be next best thing.

rake.init("rails", [task, *args])
rake.load_rakefile
rake.standard_exception_handling { rake.top_level }
end
end

Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/tasks/statistics.rake
Expand Up @@ -3,7 +3,7 @@
# While global constants are bad, many 3rd party tools depend on this one (e.g
# rspec-rails & cucumber-rails). So a deprecation warning is needed if we want
# to remove it.
STATS_DIRECTORIES = [
STATS_DIRECTORIES ||= [
%w(Controllers app/controllers),
%w(Helpers app/helpers),
%w(Jobs app/jobs),
Expand Down