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

print spring client pid on command run #455

Merged
merged 3 commits into from
Dec 14, 2015

Conversation

sonalkr132
Copy link
Contributor

Resolves #407

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@grosser
Copy link
Collaborator

grosser commented Dec 12, 2015

how about:

  • when started via spring rails xxx don't print
  • when started via rails xxx print by default ?

@sonalkr132
Copy link
Contributor Author

@grosser I don't know if I got this right, but for this we need to differentiate between two types of commands (namely spring rails/rake xxx and rails/rake xxx).
This line is the first thing that gets called:

Spring::Client.run(ARGV)

ARGV is same for both cases (spring rails c and rails c). Probably cause bin/rails acts a stand-in and just delegates commands to bin/spring leaving no difference between two commands.
Can you think of a way to differentiate between two commands?

@grosser
Copy link
Collaborator

grosser commented Dec 13, 2015

$0 for bin/rails is ./bin/rails and for spring is rails_runner

On Sat, Dec 12, 2015 at 9:11 PM, Aditya Prakash [email protected]
wrote:

@grosser https://github.com/grosser I don't know if I got this right,
but for this we need to differentiate between two types of commands (namely spring
rails/rake xxx and rails/rake xxx).
This https://github.com/rails/spring/blob/master/bin/spring#L49 line is
probably the first line that gets called:

Spring::Client.run(ARGV)

ARGV is same for both cases (spring rails c and rails c). Probably cause
bin/rails acts a stand-in and just delegates commands to bin/spring
leaving no difference between two commands.
Can you think of a way to differentiate between two commands?


Reply to this email directly or view it on GitHub
#455 (comment).

@sonalkr132
Copy link
Contributor Author

done!

@@ -46,4 +46,5 @@ end
lib = File.expand_path("../../lib", __FILE__)
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib) # enable local development
require 'spring/client'
Spring.verbose_output = false if $0.include? 'spring' # don't output running spring status if command has `spring` in it
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about: Spring.verbose_output = $0.include?('spring')

Copy link
Collaborator

Choose a reason for hiding this comment

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

the comment repeats the code, how about:

if the user knows that spring is called, do not show that spring is called

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how about: Spring.verbose_output = $0.include?('spring')

I think you meant Spring.verbose_output = !$0.include?('spring')
It is not going to work cause it will set Spring.verbose_output to true when command includesspring, even when user has Spring.verbose_output = false defined in config/spring.rb (or ~/.spring.rb).

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah yeah, makes sense

On Sat, Dec 12, 2015 at 11:44 PM, Aditya Prakash [email protected]
wrote:

In bin/spring
#455 (comment):

@@ -46,4 +46,5 @@ end
lib = File.expand_path("../../lib", FILE)
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib) # enable local development
require 'spring/client'
+Spring.verbose_output = false if $0.include? 'spring' # don't output running spring status if command has spring in it

how about: Spring.verbose_output = $0.include?('spring')

I think you meant Spring.verbose_output = !$0.include?('spring')
It is not going to work it will set Spring.verbose_output to true when
command includesspring, even when user has Spring.verbose_output = false
defined in config/spring.rb (or ~/.spring.rb).


Reply to this email directly or view it on GitHub
https://github.com/rails/spring/pull/455/files#r47441438.

@grosser
Copy link
Collaborator

grosser commented Dec 13, 2015

👍 @jonleighton looks good ?

@sonalkr132 sonalkr132 force-pushed the notif-running branch 6 times, most recently from 652d544 to e06c4fd Compare December 13, 2015 08:27
@@ -49,4 +49,6 @@ def find_project_root(current_dir)
end
end
end

self.verbose_output = true
Copy link
Member

Choose a reason for hiding this comment

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

Calling the option "verbose" makes me think that it produces more than the normal amount of output. However the default is "verbose" mode.

I'd call this Spring.quiet instead, and have it default to false. Then you're opting in to quietness, rather than the opting out of verbosity. (I also think the _output bit is superfluous.)

@jonleighton
Copy link
Member

Made some comments but generally 👍

@sonalkr132
Copy link
Contributor Author

@jonleighton @grosser Thanks for getting me through it 😝

I have made the changes you requested.

@@ -94,6 +102,22 @@ def without_gem(name)
refute app.spring_env.server_running?
end

test "running spring status for rails/rake commands" do
Copy link
Collaborator

Choose a reason for hiding this comment

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

these descriptions could make it easier for other users to understand what is being tested:

test "tells the user that spring is being used when used automatically via binstubs"
test "does not tell the user that spring is being used when the user used spring manually"
test "does not tell the user that spring is being when used automatically via binstubs but quiet is enabled"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.

@grosser
Copy link
Collaborator

grosser commented Dec 14, 2015

thx, I'll merge when travis is green :)

@sonalkr132
Copy link
Contributor Author

hey, a quick question: Is watch_interval config serving any purpose? It is mentioned in lib/spring/watcher.rb but never really used any where else in repo. Check this

@grosser
Copy link
Collaborator

grosser commented Dec 14, 2015

looks unused ... can you make a cleanup PR to remove it ?

On Mon, Dec 14, 2015 at 9:41 AM, Aditya Prakash [email protected]
wrote:

hey, a quick question: Is watch_interval config serving any purpose? It
is mentioned in lib/spring/watcher.rb but never really used any where
else in repo. Check this
https://github.com/rails/spring/search?utf8=%E2%9C%93&q=watch_interval


Reply to this email directly or view it on GitHub
#455 (comment).

@grosser
Copy link
Collaborator

grosser commented Dec 14, 2015

here we got!

grosser added a commit that referenced this pull request Dec 14, 2015
print spring client pid on command run
@grosser grosser merged commit 47a4e71 into rails:master Dec 14, 2015
@grosser
Copy link
Collaborator

grosser commented Dec 14, 2015

have fun with 1.6.0 :)

@sonalkr132
Copy link
Contributor Author

yay 🎉

@jonleighton
Copy link
Member

hey, a quick question: Is watch_interval config serving any purpose? It is mentioned in lib/spring/watcher.rb but never really used any where else in repo. Check this

I think I just put it there to avoid having magic numbers in the code. I don't think we should hardcode something like this.

@sonalkr132
Copy link
Contributor Author

Is watch_interval config serving any purpose? It is mentioned in lib/spring/watcher.rb but never really used any where else in repo

looks unused ... can you make a cleanup PR to remove it?

I was wrong that it is not serving any purpose. (check this travis run).
@jonleighton is it defined in some library spring is using? Which class behavior does it affect?

@@ -1,3 +1,4 @@
require "spring/commands"
Copy link

Choose a reason for hiding this comment

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

@sonalkr132 hey, quick question. I was wondering why you added this line? I'm getting an exception which seems to go away when I remove this line (which I've logged here).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to require spring/command cause it loads the user defined config files (config/spring.rb or ~/.spring.rb).

If user has defined Spring.quite on one of those files then we need different behavior here:

puts "Running via Spring preloader in process #{pid}" unless Spring.quiet

Copy link

Choose a reason for hiding this comment

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

Got it, thanks!

Copy link
Member

Choose a reason for hiding this comment

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

@sonalkr132 @grosser I missed this, but we shouldn't be requiring spring/commands in the client. apart from this issue that @hsume2 reported, loading bundler in the client slows down the execution of spring commands, which is exactly what we want to avoid. The client needs to run as quickly as possible.

For client-side configuration, there is the config/spring_client.rb file, so in theory the user could set Spring.quiet in there (although I don't think this is really something we need to document...)

After fixing this, it would be great if we could somehow prevent a similar bug from being reintroduced in the future (perhaps we can somehow write a test which asserts that bundler is not present in the client? I don't know)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So,Spring.quite option can only be set in spring_client.rb?

Copy link
Member

Choose a reason for hiding this comment

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

With the current implementation, I think the answer should be yes. However I think that actually we could write this "Running via Spring preloader" message in Application#serve, by which point spring/commands would be loaded. So I think that may be a better option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants