-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 lifecycle callbacks #1184
Comments
@tobymurray-nanometrics I am open to the idea. Could you submit a patch? |
I could take a look at it, sure. No guarantees on timeliness... If anyone is looking for the same functionality from the current Sinatra, we've added an extra layer on top of
|
Taking this! Will have something early next week. |
The PR is ready for this. If anyone could have a look that would be wonderful! |
This PR adds lifecycle events to Sinatra. Related issue: #1184 Co-authored-by: Patrik Ragnarsson <patrik@starkast.net>
Resolved by #1913 |
Description
Looking at the (admittedly not super popular) questions on StackOverflow like this and this, I think it'd be handy to have some usable lifecycle callbacks for Sinatra. In particular, a callback when Sinatra is completely set up and a callback when Sinatra has completely stopped.
Use case
We use JRuby for a Rails application, but we also use Java code. The Ruby code calls out to a Java HTTP client, so when we're writing tests for that code we can't use any Ruby mocking libraries. Instead of an elaborate refactor whereby a mock Java HTTP client can be injected for testing, we use a number of tiny Sinatra servers that have very simple and predetermined responses to "mock" the third party servers. So far it has worked excellently, and allows us to keep our testing and production code very similar (mocks have bitten us by not failing in ways their production equivalents would).
To accomplish this, we've mashed together something like the linked answers above whereby we block until Sinatra has started. Unfortunately, there doesn't seem to be a similar solution for
stop!
, so rapidly starting and stopping Sinatra servers occasionally fails (client can't connect). My suspicion right now is that the previous Sinatra server has not fully stopped before the next one is attempting to start.For us it'd be extremely useful to have an
on_start
andon_quit
(with whatever names are appropriate for the lifecycle which would indicate Sinatra is completely up, running, and ready to go and completely stopped).The text was updated successfully, but these errors were encountered: