From b6326c9144b6bb6e24e1e249e9e9b8cb368d758b Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 14 Feb 2022 23:40:21 +0800 Subject: [PATCH] Ign session on watch --- service/service.go | 8 ++++++++ service/watch.go | 12 ++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/service/service.go b/service/service.go index e6a73f2a..304d1e1b 100644 --- a/service/service.go +++ b/service/service.go @@ -45,6 +45,14 @@ func StartWithouttSession() { Middlewares...) } +// StopWithouttSession 关闭服务 +func StopWithouttSession(onComplete func()) { + shutdown <- true + <-shutdownComplete + gou.KillPlugins() + onComplete() +} + // Stop 关闭服务 func Stop(onComplete func()) { shutdown <- true diff --git a/service/watch.go b/service/watch.go index ed6afc41..92247d3f 100644 --- a/service/watch.go +++ b/service/watch.go @@ -67,7 +67,7 @@ func WatchGlobal(root string) { fmt.Println(color.RedString("Fatal: %s", err.Error())) return } - Stop(func() { + StopWithouttSession(func() { fmt.Println(color.GreenString("Service Restarted")) go StartWithouttSession() }) @@ -137,7 +137,7 @@ func WatchAPI(root string, prefix string) { // 重启服务器 if op == "write" || op == "create" || op == "remove" || op == "rename" { - Stop(func() { + StopWithouttSession(func() { fmt.Println(color.GreenString("Service Restarted")) go StartWithouttSession() }) @@ -268,7 +268,7 @@ func WatchTable(root string, prefix string) { // 重启服务器 if op == "write" || op == "create" || op == "remove" || op == "rename" { - Stop(func() { + StopWithouttSession(func() { fmt.Println(color.GreenString("Service Restarted")) go StartWithouttSession() }) @@ -335,7 +335,7 @@ func WatchChart(root string, prefix string) { // 重启服务器 if op == "write" || op == "create" || op == "remove" || op == "rename" { - Stop(func() { + StopWithouttSession(func() { fmt.Println(color.GreenString("Service Restarted")) go StartWithouttSession() }) @@ -402,7 +402,7 @@ func WatchPage(root string, prefix string) { // 重启服务器 if op == "write" || op == "create" || op == "remove" || op == "rename" { - Stop(func() { + StopWithouttSession(func() { fmt.Println(color.GreenString("Service Restarted")) go StartWithouttSession() }) @@ -450,7 +450,7 @@ func WatchWorkFlow(root string, prefix string) { // 重启服务器 if op == "write" || op == "create" || op == "remove" || op == "rename" { - Stop(func() { + StopWithouttSession(func() { fmt.Println(color.GreenString("Service Restarted")) go StartWithouttSession() })