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
Allow extra runtime deps to be defined when using prune_bundler #1105
Conversation
Upon further testing it looks like this won't worker for bundler gem installed from git as https://github.com/puma/puma/blob/master/bin/puma-wild#L20 calls Maybe the best way forward is to resolve needed gem paths before forking (at the top of config/puma.rb), and then adding them to the load path after fork? |
36af314
to
72ec33d
Compare
Not running the extra dependencies through the |
Paging @schneems |
Hi, I wrote puma worker killer. Does it work if in a I've not used |
Before submitting it this way I attempted to load puma worker killer using bundler in the I could have copy-pasted the logic behind |
Any update on this PR? |
Hi, we've encountered a usecase for this inside one of our production applications - I notice that CI is failing on unrelated tests to this PR, has any of the maintainers had a chance to review the comment made by @daveallie on 07/12/2016. Thanks |
@Dombo can you expand on your use-case? Same as @daveallie's? |
@nateberkopec sorry if I wasn't clear but yes it's the same use case as @daveallie's |
@nateberkopec any chance of moving this PR forward? It's almost been a year and nothing has really happened. |
1348b8b
to
119172d
Compare
Hi @nateberkopec or @schneems. Just thought I'd ping this again. Every time I want to use Puma master I need to rebase these changes on top.
|
lib/puma/launcher.rb
Outdated
@@ -262,6 +262,17 @@ def prune_bundler | |||
"#{d.name}:#{spec.version.to_s}" | |||
end | |||
|
|||
if @options[:extra_runtime_dependencies] |
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 is always true
.
lib/puma/launcher.rb
Outdated
@@ -262,6 +262,17 @@ def prune_bundler | |||
"#{d.name}:#{spec.version.to_s}" | |||
end | |||
|
|||
if @options[:extra_runtime_dependencies] | |||
@options[:extra_runtime_dependencies].each do |d_name| | |||
spec = Bundler.rubygems.loaded_specs(d_name) rescue nil |
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.
Rather than a rescue nil
, we should do a proper begin/rescue here, which will get rid of the the if/else
.
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.
There's actually no need for a rescue here at all, I don't know what I was thinking https://www.rubydoc.info/github/bundler/bundler/Bundler/RubygemsIntegration#loaded_specs-instance_method, loaded_specs
is just a hash lookup.
lib/puma/launcher.rb
Outdated
if spec | ||
dirs += spec.require_paths.map { |x| File.join(spec.full_gem_path, x) } | ||
else | ||
log "* Couldn't to load extra dependency: #{d_name}" |
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.
"Couldn't to"
lib/puma/dsl.rb
Outdated
# When using prune_bundler, if extra runtime dependencies need to be loaded to | ||
# initialize your app, then this setting can be used. | ||
# | ||
# For each gem's name passed, that gem will be loaded when the environment |
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.
"each gem name passed"
Can people accept a Bundler version requirement for this feature? It's currently bugged because the require paths are wrong. I'd rather just use
|
Also there's no way we can merge this without tests. |
Here's some ideas for refactoring this method while we're here. https://gist.github.com/nateberkopec/386db42c0eb3fe4fa91b009dd9f1f84b |
Apologies for the sloppy nature of this PR, will bring it up to scratch |
So rubygem's |
119172d
to
eb90d3e
Compare
Extra gems are sometimes needed in the
before_fork
block or before Bundler gets loaded on the workers. This PR adds the ability to define any extra bundler gems to load when pruning bundler.As an example, when using https://github.com/schneems/puma_worker_killer, it should be loaded in the before_fork of the
config/puma.rb
file like so:If you have installed the gem from the github repo, and are using the
prune_bundler
option, therequire 'puma_worker_killer'
will fail. The only way to get it to run is to require bundler, and then require the gem in the context of bundler. Which, if you're also attempting to prune bundler, completely defeats the purpose and means gems aren't reloaded across phased restarts.