This commit is contained in:
crusader 2018-03-26 12:50:29 +09:00
parent cf4820d89b
commit e6f66ad7f0
7 changed files with 24 additions and 28 deletions

View File

@ -1,6 +1,7 @@
package auth
import (
"context"
"fmt"
"path"
"sync"
@ -9,6 +10,7 @@ import (
"git.loafle.net/commons_go/logging"
crr "git.loafle.net/commons_go/rpc/registry"
ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe"
oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces"
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
"git.loafle.net/overflow/overflow_probes/auth/client"
oopas "git.loafle.net/overflow/overflow_probes/auth/service"
@ -22,8 +24,8 @@ func New() AuthManager {
}
type AuthManager interface {
EndableStart(doneChan chan<- error) error
Stop()
oocmci.EndableStarter
oocmci.Stopper
}
type authManagers struct {
@ -85,8 +87,10 @@ func (am *authManagers) EndableStart(doneChan chan<- error) error {
return nil
}
func (am *authManagers) Stop() {
func (am *authManagers) Stop(ctx context.Context) error {
am.destroy(nil)
return nil
}
func (am *authManagers) destroy(err error) {

View File

@ -1,5 +0,0 @@
package commons
type EndableStarter interface {
EndableStart(endded chan<- error) error
}

View File

@ -1,7 +0,0 @@
package commons
import "context"
type Shutdowner interface {
Shutdown(ctx context.Context) error
}

View File

@ -1,5 +0,0 @@
package commons
type Starter interface {
Start() error
}

View File

@ -14,8 +14,8 @@ import (
"git.loafle.net/commons_go/logging"
oocc "git.loafle.net/overflow/overflow_commons_go/config"
ooccp "git.loafle.net/overflow/overflow_commons_go/config/probe"
oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces"
"git.loafle.net/overflow/overflow_probes/auth"
"git.loafle.net/overflow/overflow_probes/commons"
"git.loafle.net/overflow/overflow_probes/config"
"git.loafle.net/overflow/overflow_probes/probe"
)
@ -71,7 +71,7 @@ func main() {
authDoneChan := make(chan error, 1)
defer close(authDoneChan)
if err := instance.(commons.EndableStarter).EndableStart(authDoneChan); err != nil {
if err := instance.(oocmci.EndableStarter).EndableStart(authDoneChan); err != nil {
logging.Logger().Error(err)
os.Exit(1)
}
@ -82,7 +82,7 @@ func main() {
}
}
instance = probe.New()
if err := instance.(commons.Starter).Start(); err != nil {
if err := instance.(oocmci.Starter).Start(); err != nil {
logging.Logger().Error(err)
os.Exit(1)
}
@ -104,7 +104,7 @@ func main() {
<-interrupt
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := instance.(commons.Shutdowner).Shutdown(ctx); err != nil {
if err := instance.(oocmci.Stopper).Stop(ctx); err != nil {
logging.Logger().Errorf("Probe error: %v", err)
}

View File

@ -1,11 +1,13 @@
package probe
import (
"context"
"sync"
cdr "git.loafle.net/commons_go/di/registry"
"git.loafle.net/commons_go/logging"
crr "git.loafle.net/commons_go/rpc/registry"
oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces"
oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client"
oopccd "git.loafle.net/overflow/overflow_probes/client/central/data"
@ -21,8 +23,8 @@ func New() ProbeManager {
}
type ProbeManager interface {
Start() error
Stop()
oocmci.Starter
oocmci.Stopper
}
type probeManagers struct {
@ -78,7 +80,7 @@ func (pm *probeManagers) Start() error {
return nil
}
func (pm *probeManagers) Stop() {
func (pm *probeManagers) Stop(ctx context.Context) error {
if pm.stopChan == nil {
logging.Logger().Warnf("Probe: probe must be started before stopping it")
}
@ -90,13 +92,14 @@ func (pm *probeManagers) Stop() {
logging.Logger().Infof("Probe: stopped")
return nil
}
func (pm *probeManagers) handleProbe() {
// var err error
defer func() {
pm.stopWg.Done()
pm.Stop()
pm.Stop(nil)
}()
// if err = pm.cClient.Connect(); nil != err {

View File

@ -3,6 +3,12 @@ package service
func InitService() {
}
func StartService() {
}
func StopService() {
}
func DestroyService() {
}