Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Toby Yan <me@tobyan.com>
- Loading branch information
Showing
6 changed files
with
77 additions
and
55 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package graceful | ||
|
||
import ( | ||
"github.com/totoval/framework/helpers/log" | ||
"github.com/totoval/framework/helpers/toto" | ||
) | ||
|
||
func panicRecover(quietly bool) { | ||
if err := recover(); err != nil { | ||
logFatal(quietly, "Totoval shutting down failed", toto.V{"error": err}) | ||
} | ||
} | ||
|
||
func logInfo(quietly bool, msg string, v ...toto.V) { | ||
if !quietly { | ||
log.Info(msg, v...) | ||
} | ||
} | ||
func logFatal(quietly bool, msg string, v ...toto.V) { | ||
if !quietly { | ||
log.Fatal(msg, v...) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package graceful | ||
|
||
import ( | ||
"github.com/totoval/framework/cache" | ||
"github.com/totoval/framework/helpers/m" | ||
"github.com/totoval/framework/helpers/toto" | ||
"github.com/totoval/framework/monitor" | ||
"github.com/totoval/framework/queue" | ||
) | ||
|
||
func closeQueue(quietly bool) { | ||
defer panicRecover(quietly) | ||
logInfo(quietly, "Queue closing") | ||
if err := queue.Queue().Close(); err != nil { | ||
logFatal(quietly, "queue close failed", toto.V{"error": err}) | ||
} | ||
logInfo(quietly, "Queue closed") | ||
} | ||
func closeDB(quietly bool) { | ||
defer panicRecover(quietly) | ||
logInfo(quietly, "Database closing") | ||
if err := m.H().DB().Close(); err != nil { | ||
logFatal(quietly, "database close failed", toto.V{"error": err}) | ||
} | ||
logInfo(quietly, "Database closed") | ||
} | ||
func closeCache(quietly bool) { | ||
defer panicRecover(quietly) | ||
logInfo(quietly, "Cache closing") | ||
if err := cache.Cache().Close(); err != nil { | ||
logFatal(quietly, "cache close failed", toto.V{"error": err}) | ||
} | ||
logInfo(quietly, "Cache closed") | ||
} | ||
func closeMonitor(quietly bool) { | ||
defer panicRecover(quietly) | ||
logInfo(quietly, "Monitor closing") | ||
if err := monitor.Shutdown(); err != nil { | ||
logFatal(quietly, "monitor close failed", toto.V{"error": err}) | ||
} | ||
logInfo(quietly, "Monitor closed") | ||
} |
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 |
---|---|---|
@@ -1,59 +1,10 @@ | ||
package graceful | ||
|
||
import ( | ||
"github.com/totoval/framework/cache" | ||
"github.com/totoval/framework/helpers/log" | ||
"github.com/totoval/framework/helpers/m" | ||
"github.com/totoval/framework/helpers/toto" | ||
"github.com/totoval/framework/queue" | ||
) | ||
|
||
func ShutDown(quietly bool) { | ||
logInfo(quietly, "Totoval is shutting down") | ||
closeQueue(quietly) | ||
closeCache(quietly) | ||
closeDB(quietly) | ||
closeMonitor(quietly) | ||
logInfo(quietly, "Totoval is shut down") | ||
} | ||
|
||
func closeQueue(quietly bool) { | ||
defer panicRecover(quietly) | ||
logInfo(quietly, "Queue closing") | ||
if err := queue.Queue().Close(); err != nil { | ||
logFatal(quietly, "queue close failed", toto.V{"error": err}) | ||
} | ||
logInfo(quietly, "Queue closed") | ||
} | ||
func closeDB(quietly bool) { | ||
defer panicRecover(quietly) | ||
logInfo(quietly, "Database closing") | ||
if err := m.H().DB().Close(); err != nil { | ||
logFatal(quietly, "database close failed", toto.V{"error": err}) | ||
} | ||
logInfo(quietly, "Database closed") | ||
} | ||
func closeCache(quietly bool) { | ||
defer panicRecover(quietly) | ||
logInfo(quietly, "Cache closing") | ||
if err := cache.Cache().Close(); err != nil { | ||
logFatal(quietly, "cache close failed", toto.V{"error": err}) | ||
} | ||
logInfo(quietly, "Cache closed") | ||
} | ||
|
||
func panicRecover(quietly bool) { | ||
if err := recover(); err != nil { | ||
logFatal(quietly, "Totoval shutting down failed", toto.V{"error": err}) | ||
} | ||
} | ||
|
||
func logInfo(quietly bool, msg string, v ...toto.V) { | ||
if !quietly { | ||
log.Info(msg, v...) | ||
} | ||
} | ||
func logFatal(quietly bool, msg string, v ...toto.V) { | ||
if !quietly { | ||
log.Fatal(msg, v...) | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package monitor | ||
|
||
import "github.com/totoval/framework/monitor/app/logics/dashboard" | ||
|
||
func Shutdown() error { | ||
dashboard.Flow.Close() | ||
return nil | ||
} |