-
Notifications
You must be signed in to change notification settings - Fork 20
Fix clean etc #104
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
base: master
Are you sure you want to change the base?
Fix clean etc #104
Conversation
exe/solr_wrapper
Outdated
| @@ -1,5 +1,9 @@ | |||
| #!/usr/bin/env ruby | |||
|
|
|||
| if ENV['RAILS_ENV'] && ENV['RAILS_ENV'] == 'production' | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gem doesn't require rails, so a dependency on RAILS_ENV is inappropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't depend on it, it just checks for an ENV value, that always works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's an appropriate check for this gem to make. While I think it's a bad idea for someone to want to do that, this gem has no place enforcing that.
exe/solr_wrapper
Outdated
| $stderr.puts "Please stop solr before cleaning" | ||
| exit 1 | ||
| end | ||
| return if ENV['RAILS_ENV'] && ENV['RAILS_ENV'] == 'production' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gem doesn't use rails, so a dependency on RAILS_ENV is inappropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
lib/solr_wrapper/instance.rb
Outdated
| ## | ||
| # Is Solr running? | ||
| def started? | ||
| status =~ /running on port #{port}/ && true || false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The boolean logic at the end makes no sense to me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal preference, I like to see actual true or false instead of truthy or falsy values and this satisfies that craving.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change it for this project.
lib/solr_wrapper/instance.rb
Outdated
|
|
||
| ## | ||
| # Check the status of a managed Solr service | ||
| def status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a backwards-compatible change in behavior for #status? Could we extract this behavior to a different method name instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it is only ever called locally and all those calls use started? instead, it doesn't matter (at least the specs don't care, so that's goog enough for me, esp. if this is all private anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#status is in the public api for SolrWrapper::Instance, is it not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, so it is. But it could be private and seems to operate as private. I dunno. Maybe a major version change? I like the name status for this method. I started with status_info and then status did what started? does now and basically started? can be an alias for status. I could go back to that if this API is important to maintain.
lib/solr_wrapper/instance.rb
Outdated
| exec('status').read | ||
| rescue | ||
| false | ||
| 'No status information available' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we provide a little more context in this error message? At the very least, knowing what we rescued could go a long way to aiding debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really an error message, it's a status message that there is not status info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... which only happens in exceptional cases. I'm 👍 to giving users better access to this status information, but if we're going to do that, we should also give them enough information when things are going wrong.
| def clean! | ||
| stop | ||
| remove_instance_dir! | ||
| FileUtils.remove_entry(config.download_dir, true) if File.exist?(config.download_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of removing this line whole-sale, let's put it behind a named parameter flag (say, #clean! except_download_dir: true, or something better). There's a real use-case for "get rid of everything solr_wrapper has done", and I want to preserve that ability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean vs. clean! maybe? where the latter calls this clean and then also cleans up the downloads (all of them).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A ! suffix usually indicates dangerousness or mutating state, neither of which seem to be true here. I'd rather we make it an opt-in/-out flag.
| return if ENV['RAILS_ENV'] && ENV['RAILS_ENV'] == 'production' | ||
| $stderr.puts "cleaning #{instance.instance_dir}..." | ||
| instance.remove_instance_dir! | ||
| instance.clean! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not clear on why this change was made?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clean! calls stop so that's the big diff. Given that, then it's not necessary to check if it's stopped, it will get stopped.
solr_wrapper.gemspec
Outdated
| spec.add_development_dependency "bundler", "~> 1.7" | ||
| spec.add_development_dependency "rake", "~> 10.0" | ||
|
|
||
| spec.add_development_dependency "pry" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this commit. I'm not interested in this gem requiring pry for development.
- do not allow solr_wrapper in production, esp. clean
- status returns an info string, use started? for boolean
- status and started? do not check managed? because it's not reliable
- clean command actually runs clean!
- do not clean up the downloaded .zip file
98e783c to
5be1436
Compare
47b41ac to
d684ae9
Compare
|
Addressed comments, leaving commits for checking details, can squash as required later. |
cbeer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this doesn't address some of the comments I made earlier. I'll review it again tomorrow.
it is a very common practice for gems that don't depend on/require rails to still check for Often gems will first check for a "${GEM_NAME}_ENV", lazily resorting to I disagree with avoiding this develper convenience in the name of some kind of purity that has really no cost at all. Examples: Many web servers use both Sidekiq also uses An alternative might be allowing setting of 'ENV' in the .solr_wrapper file (which is run through erb), so the user could choose to set it to |
|
That said, I'm not sure what this PR is doing with RAILS_ENV is what I'd do, but it still seems like progress to me. Things get very confusing at present, anything to reduce the confusion would be great. In my ideal world, I'd have one config file that had env-specific |
lib/solr_wrapper/instance.rb
Outdated
| return true unless config.managed? | ||
| # Is Solr running? | ||
| def started? | ||
| status_info =~ /running on port #{port}/ && true || false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I commented on this previously. Please remove && true || false. It should be sufficient that started? return a truthy value. If that isn't the case, let's be explicit about that using match() and checking for a return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, deferring to your preference on this. Removing it. (Aside, I'm curious and open to using an explicit match() way of doing as an alternative coding style; rubocop doesn't approve of !!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm going to push up another commit to replace this with an String#include? call instead, which seems cleaner and could be faster although that's not important here.
lib/solr_wrapper/instance.rb
Outdated
| # Clean up any files solr_wrapper may have downloaded | ||
| def clean! | ||
| # Clean up any files solr_wrapper may have downloaded, except the solr-{ver}.zip file | ||
| def clean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is our previous discussion:
@cbeer
cbeer 12 days ago Owner
Instead of removing this line whole-sale, let's put it behind a named parameter flag (say, #clean! except_download_dir: true, or something better). There's a real use-case for "get rid of everything solr_wrapper has done", and I want to preserve that ability.
@darrenleeweber
darrenleeweber 12 days ago
clean vs. clean! maybe? where the latter calls this clean and then also cleans up the downloads (all of them).
@cbeer
cbeer 12 days ago Owner
A ! suffix usually indicates dangerousness or mutating state, neither of which seem to be true here. I'd rather we make it an opt-in/-out flag.
I see you chose to use clean and clean! instead, which surprises me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, pushing up something with #clean! clean_downloads: false, so the default action is not to clean up the downloads. The commit also focuses on removing files only (.md5, .zip download files) and not the entire download directory (in case anyone sets .solr_wrapper with a download_dir like ~/Downloads). The more likely scenario is that multiple projects use different versions of solr and share a download_dir, so any instance of solr_wrapper should clean up only the files configured for this instance (or project).
|
|
Obviously some squashing is required before a merge. I'm only leaving individual commits for the sake of review in the PR, to help track the review requirements/discussion. |
exe/solr_wrapper
Outdated
| instance.clean! | ||
| when 'purge' | ||
| $stderr.puts "cleaning solr downloads and solr instance: #{instance.instance_dir} ..." | ||
| instance.clean!(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be instance.clean!(clean_downloads: true)?
|
My |
f09af9b to
d5106cf
Compare
|
@cbeer - bump |
|
@cbeer - reminder.... |
Might fix #83
solr_wrapper cleanwas often reporting that solr has to be stopped before cleaning it, when solr was never running in the first place. This bugged me often enough that it motived a fork and these changes. Throwing up this PR for consideration, maybe it's useful upstream.Added some other command-line utils, including
statusandstop. They are working for me. No specs needed to change for this PR, everything was passing OK on my laptop.Example of using this branch: