From ddb4aae693b4cb168718228db61332e0387593f2 Mon Sep 17 00:00:00 2001
From: Hans Moog <hm@mkjc.net>
Date: Fri, 29 Mar 2019 07:08:02 +0100
Subject: [PATCH] Refactor: refactored gracefulshutdown plugin

---
 plugins/gracefulshutdown/constants.go |  4 ----
 plugins/gracefulshutdown/plugin.go    | 14 ++++++++------
 2 files changed, 8 insertions(+), 10 deletions(-)
 delete mode 100644 plugins/gracefulshutdown/constants.go

diff --git a/plugins/gracefulshutdown/constants.go b/plugins/gracefulshutdown/constants.go
deleted file mode 100644
index e63ac569..00000000
--- a/plugins/gracefulshutdown/constants.go
+++ /dev/null
@@ -1,4 +0,0 @@
-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
diff --git a/plugins/gracefulshutdown/plugin.go b/plugins/gracefulshutdown/plugin.go
index cd6bc693..e09f87f9 100644
--- a/plugins/gracefulshutdown/plugin.go
+++ b/plugins/gracefulshutdown/plugin.go
@@ -10,8 +10,12 @@ import (
     "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)
+
     signal.Notify(gracefulStop, syscall.SIGTERM)
     signal.Notify(gracefulStop, syscall.SIGINT)
 
@@ -26,9 +30,9 @@ func run(plugin *node.Plugin) {
                 secondsSinceStart := x.Sub(start).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 {
-                    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)
                 }
@@ -37,6 +41,4 @@ func run(plugin *node.Plugin) {
 
         daemon.Shutdown()
     }()
-}
-
-var PLUGIN = node.NewPlugin("Graceful Shutdown", run)
+})
-- 
GitLab