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
Add on_booted event #2709
Add on_booted event #2709
Conversation
d30be15
to
94e7d64
Compare
Thank you so much for your first contrib to Puma! Welcome to the team! |
Thanks for a warm welcome! |
@nateberkopec One simple way that it could be achieved is to give a possibility for DSLs to have access to the events object. I did that in the latest commit |
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 have much useful guidance on the implementation, but I was able to make the test you added pass with a change that might help you find the right path for this feature.
f0304fb
to
6112487
Compare
Needs a test and I think it's good to go? |
lib/puma/dsl.rb
Outdated
@@ -588,6 +592,17 @@ def after_worker_fork(&block) | |||
@options[:after_worker_fork] << block | |||
end | |||
|
|||
# Code to run after puma is booted in a single mode | |||
# | |||
# @note Single mode only. |
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.
Why this would be Single mode only? Cluster mode also calls fire(:on_booted)
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.
Johnny is correct:
Line 468 in 5f255fc
@launcher.events.fire_on_booted! |
Line 477 in 5f255fc
@events.fire_on_booted! |
I guess the docs was written like this because the request (#2635, #1230 (comment)) came from a user using single mode where after_worker_boot
(aliased to after_worker_fork
) doesn't exist.
Line 104 in 5f255fc
@launcher.config.run_hooks :after_worker_fork, idx, @launcher.events |
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.
Thanks for catching this, correct it runs for both, clustered and single mode, I've changed the description. The question is, what would be the expected behavior? At the end the name of the event is on_booted
so I think it makes sense to be run on both: single and clutered. Any thoughts @nateberkopec ?
lib/puma/dsl.rb
Outdated
@@ -251,6 +251,10 @@ def bind_to_activated_sockets(bind=true) | |||
@options[:bind_to_activated_sockets] = bind | |||
end | |||
|
|||
def events(events) | |||
@options[:events] = events | |||
end |
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.
Do we need to add events
to the DSL? Should we document it? Looks like some kind of hack to me? :) Should it be a public thing in the DSL?
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.
Should the other DSL objects also have access to @events
?
puma/lib/puma/configuration.rb
Lines 146 to 148 in 5f255fc
@user_dsl = DSL.new(@options.user_options, self) | |
@file_dsl = DSL.new(@options.file_options, self) | |
@default_dsl = DSL.new(@options.default_options, self) |
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 was long time ago, but I think it was result of this discussion: #2709 (comment)
It was made as a temporary measure, to be refactored later I guess. I'm not sure if that is still right approach
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 have changed the behavior, so now there is no need for this method and the Puma::Events
instance is passed early to Puma::Configuration
so it can be used by any type of DSL if needed
We just merged #2798 which affects events, so please pull latest master to this branch. |
Can this be merged? I also need this functionality. |
8e0f32c
to
0799018
Compare
Sorry for abandoning this work for a long time. I had a very busy personal life in the past few months. I'm back with more time so I did a rebase. I will also try to look once again into a solution. |
Any update on this? |
If you don't have multiple processes, can't you just... run your code directly in # [the default rails puma.rb file goes here]
require "sidekiq"
require_relative "initializers/sidekiq"
sidekiq = Sidekiq.configure_embed do |config|
# config.logger.level = Logger::DEBUG
config.queues = %w[critical default low]
config.concurrency = 2
end
sidekiq.run
at_exit do
sidekiq&.stop
end |
Not necessarily. My use case involves running both single process and multi process based on environment. And I need the on booted event to fire correctly in both cases. |
daa138b
to
f4575cd
Compare
Looks like you've done a git-whoopsie and deleted your test. |
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.
Fix tests
cf01e9a
to
33da1e1
Compare
33da1e1
to
1b7c021
Compare
1b7c021
to
6ba097e
Compare
196f445
to
627261d
Compare
627261d
to
ca69608
Compare
@nateberkopec @dentarg - feel free to take a look if you have time whether these changes make sense |
ca69608
to
e0fe05d
Compare
Merged in 7c8cb02 |
Crud, I screwed up the merge. @MSP-Greg can you take a look and try? the changes to rack/handler meant that my merge didn't work. |
Looking at it now. |
e0fe05d
to
babd019
Compare
Test are running. I think the Windows mswin job will fail, it may be a recent change in Ruby master, re an error message. All the Actions master builds are done at different times, so they're not all the same commit in ruby/ruby...
|
Done... |
🙇 Thanks! |
Description
Closes #2635
I'm not sure if exactly that is what was intended. But I'm happy to get a feedback :)
Your checklist for this pull request
[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.