From a2d21e95c1c83aa6ea33bcc8a8f56b24a2611acd Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 30 Dec 2021 16:02:28 +0300 Subject: [PATCH] refactor --- internal/app/app.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index 4d92965..4e85219 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -108,17 +108,19 @@ func Run() error { go RunPuller(ctx, errchan, rcli) default: { - cancel() - return fmt.Errorf("v8-1c-cluster-pde: %v", "undefined mode") + errchan <- fmt.Errorf("v8-1c-cluster-pde: %v", "undefined mode") } } - log.Printf("v8-1c-cluster-pde: received signal %v", - <-sigchan, - ) - cancel() - - return <-errchan + select { + case sig := <-sigchan: + cancel() + log.Printf("v8-1c-cluster-pde: received signal %v", sig) + return nil + case err := <-errchan: + cancel() + return err + } } func RunPuller(ctx context.Context, errchan chan<- error, rasapi rascli.Api) { @@ -150,7 +152,7 @@ func RunPuller(ctx context.Context, errchan chan<- error, rasapi rascli.Api) { } func RunPusher(ctx context.Context, errchan chan<- error, rasapi rascli.Api) { - log.Printf("v8-1c-cluster-pde: runing in %v mode pushgateway %v\n", + log.Printf("v8-1c-cluster-pde: runing in %v mode %v\n", conf.MODE, fmt.Sprintf("%s:%s", conf.PUSH_HOST, conf.PUSH_PORT)) go pusher.New( @@ -159,3 +161,7 @@ func RunPusher(ctx context.Context, errchan chan<- error, rasapi rascli.Api) { pusher.WithInterval(500), ).Run(ctx, errchan) } + +type RASCollector interface { + Run(ctx context.Context, errchan chan<- error, rasapi rascli.Api) +}