Skip to content
Snippets Groups Projects
Commit ddb4aae6 authored by Hans Moog's avatar Hans Moog
Browse files

Refactor: refactored gracefulshutdown plugin

parent 8eb9708c
Branches
Tags
No related merge requests found
package gracefulshutdown
// The maximum amount of time we wait for background processes to terminate. After that the process is killed.
const WAIT_TO_KILL_TIME_IN_SECONDS = 10
...@@ -10,8 +10,12 @@ import ( ...@@ -10,8 +10,12 @@ import (
"time" "time"
) )
func run(plugin *node.Plugin) { // maximum amount of time to wait for background processes to terminate. After that the process is killed.
const WAIT_TO_KILL_TIME_IN_SECONDS = 10
var PLUGIN = node.NewPlugin("Graceful Shutdown", func(plugin *node.Plugin) {
gracefulStop := make(chan os.Signal) gracefulStop := make(chan os.Signal)
signal.Notify(gracefulStop, syscall.SIGTERM) signal.Notify(gracefulStop, syscall.SIGTERM)
signal.Notify(gracefulStop, syscall.SIGINT) signal.Notify(gracefulStop, syscall.SIGINT)
...@@ -26,9 +30,9 @@ func run(plugin *node.Plugin) { ...@@ -26,9 +30,9 @@ func run(plugin *node.Plugin) {
secondsSinceStart := x.Sub(start).Seconds() secondsSinceStart := x.Sub(start).Seconds()
if secondsSinceStart <= WAIT_TO_KILL_TIME_IN_SECONDS { if secondsSinceStart <= WAIT_TO_KILL_TIME_IN_SECONDS {
plugin.LogWarning("Received shutdown request - waiting (max " + strconv.Itoa(WAIT_TO_KILL_TIME_IN_SECONDS - int(secondsSinceStart)) + " seconds) to finish processing ...") plugin.LogWarning("Received shutdown request - waiting (max " + strconv.Itoa(WAIT_TO_KILL_TIME_IN_SECONDS-int(secondsSinceStart)) + " seconds) to finish processing ...")
} else { } else {
plugin.LogFailure("The background processes did not terminate in time! Forcing shutdown ...") plugin.LogFailure("Background processes did not terminate in time! Forcing shutdown ...")
os.Exit(1) os.Exit(1)
} }
...@@ -37,6 +41,4 @@ func run(plugin *node.Plugin) { ...@@ -37,6 +41,4 @@ func run(plugin *node.Plugin) {
daemon.Shutdown() daemon.Shutdown()
}() }()
} })
var PLUGIN = node.NewPlugin("Graceful Shutdown", run)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment