-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
How to determine the status of a puma server #364
Comments
I'll add those APIs. The status is there it's just not nicely exposed. |
Great; Thanks |
@evanphx is there something quick we can do in the meantime before you have a chance to make those APIs public? |
If you must, you could use instance_variable_get to grab the @status ivar. I'd love to get some ideas about what you want to use the status for. |
Hm, ok. Looking at status isn't going to tell you much. Mostly that the beginning of #run was executed. What do you really want to know? That Puma is serving requests? What are the cases where it would not start? |
@evanphx if you start the server in the background, it may not start immediately and we need to wait until it's ready to proceed. |
I think what we are looking for is something to tell us if puma is currently available to server requests or is not. running and backlog can tell us if it is processing requests or has some waiting to process. We need to know if it is in a state where it is able to accept requests. Like when stop is call async how do we tell when the server has stopped and is no longer available to accept requests. |
Could use use |
@krisleech def running?
begin
uri = URI(@url)
if uri.host == '0.0.0.0' then uri.host = '127.0.0.1' end
Net::HTTP.get_response(uri)
rescue Errno::ECONNREFUSED
false
else
true
end
end But it feels clunky and has more potential for not behaving as intended than just being able to ask the puma server if it is up. |
@krmichelos Ah, I thought you where talking about having something external to Puma, not built-in. |
So I added a nice API for you to use! I haven't added docs for it yet, but you can check it out here: b24920d You'll want to create your own Events object and pass it into Server.new so that you can register callbacks on it. Your blocks/callbacks will be called from the thread puma is running the server in, so you can use a ConditionVariable to block until the server has fully started. |
❤️ |
When using Puma::Server I don't see a way to determine the status (running, stopped, etc.) of the server. Am I missing something or is this not possible. An example of when this would be helpful is to ensure the server is stopped after calling the stop method.
The text was updated successfully, but these errors were encountered: