-
Notifications
You must be signed in to change notification settings - Fork 170
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
Support a configurable delay before shutting down services #2238
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,11 @@ import com.beust.jcommander.ParameterException | |
import com.google.common.annotations.VisibleForTesting | ||
import com.google.common.util.concurrent.ServiceManager | ||
import com.google.inject.Guice | ||
import com.google.inject.Key | ||
import com.google.inject.Module | ||
import misk.inject.KAbstractModule | ||
import misk.inject.getInstance | ||
import misk.web.WebConfig | ||
import wisp.logging.getLogger | ||
|
||
/** The entry point for misk applications */ | ||
|
@@ -88,6 +90,10 @@ class MiskApplication(private val modules: List<Module>, commands: List<MiskComm | |
Runtime.getRuntime().addShutdownHook(object : Thread() { | ||
override fun run() { | ||
log.info { "received a shutdown hook! performing an orderly shutdown" } | ||
if (injector.getExistingBinding(Key.get(WebConfig::class.java)) != null) { | ||
val config = injector.getInstance<WebConfig>() | ||
sleep(config.shutdown_sleep_ms.toLong()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is my attempt to make the delay configurable. It's not clear to me what other avenues exist for making it possible for consumers to customize behaviour at this layer of the framework. |
||
} | ||
serviceManager.stopAsync() | ||
serviceManager.awaitStopped() | ||
log.info { "orderly shutdown complete" } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think this would make a lot more sense at the start of
JettyService#shutDown()
. Saves having to check with the injector too, and makes the functionality testable (at least, in theory—testing asleep
call probably won't be nice).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.
Unfortunately that does not actually help with the problem - the issue is with other services being shut down before the jetty service is finished servicing requests.
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 could move the sleep to the hibernate service instead, I suppose, at the risk of uncovering other services that may also be affected in the same way. Sleeping here avoids the risk of playing whack-a-mole for something that is intended to be a short-term workaround.