houstonClient 종료시 houstonServer도 종료
This commit is contained in:
@ -15,10 +15,6 @@ import (
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultMaxMemory = 32 << 10 // 32 KB
|
||||
)
|
||||
|
||||
type HoustonServerWithHandler interface {
|
||||
HoustonServer
|
||||
RegisterHandlers(serveMux *http.ServeMux, prefix string) error
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
@ -176,23 +177,35 @@ func (hs *houstonServer) Start() error {
|
||||
return err
|
||||
}
|
||||
|
||||
closeCount := int32(0)
|
||||
var hc client.HoustonClient
|
||||
if loadServerConfig().RunAsClient {
|
||||
go func() {
|
||||
time.Sleep(time.Second)
|
||||
hc, err := client.NewClient()
|
||||
hc, err = client.NewClient()
|
||||
if err != nil {
|
||||
logger.Fatal(err)
|
||||
return
|
||||
}
|
||||
hc.Start()
|
||||
}()
|
||||
}
|
||||
|
||||
if err := hs.rpcServer.Serve(lis); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
go func() {
|
||||
time.Sleep(time.Second)
|
||||
hc.Start()
|
||||
logger.Println("houstonClient is finished")
|
||||
if atomic.AddInt32(&closeCount, 1) == 1 {
|
||||
logger.Println("try stop houstonServer")
|
||||
hs.Stop()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
err = hs.rpcServer.Serve(lis)
|
||||
if atomic.AddInt32(&closeCount, 1) == 1 {
|
||||
if hc != nil {
|
||||
logger.Println("try stop houstonClient")
|
||||
hc.Shutdown()
|
||||
}
|
||||
}
|
||||
logger.Println("houstonServer is finished")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (hs *houstonServer) Stop() {
|
||||
|
||||
Reference in New Issue
Block a user