From 560c93c2e40e676f3b0a0191e5af8dd87dd6cbd3 Mon Sep 17 00:00:00 2001 From: Sangbum Kim Date: Fri, 6 Jul 2018 01:57:59 +0900 Subject: [PATCH] =?UTF-8?q?channel=20close=20=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootstrap.go | 6 +++++- consumer/speed_controller.go | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/bootstrap.go b/bootstrap.go index 1df54a9..b9fd036 100644 --- a/bootstrap.go +++ b/bootstrap.go @@ -29,6 +29,10 @@ func initLogger() func() { // 로깅설정 formatter := zapcore.NewConsoleEncoder(zlog.LogCommonFormat) + level := zap.InfoLevel + if *verbose{ + level=zap.DebugLevel + } // 전역 로거 초기화 var err error logger, err = zlog.Init( @@ -38,7 +42,7 @@ func initLogger() func() { "Stderr", "", nil, - zap.DebugLevel, + level, ) if err != nil { diff --git a/consumer/speed_controller.go b/consumer/speed_controller.go index 4985863..9d64c80 100644 --- a/consumer/speed_controller.go +++ b/consumer/speed_controller.go @@ -9,6 +9,7 @@ import ( "amuz.es/src/infra/goutils/handler" "amuz.es/src/infra/cpu_ctrl/producer" "go.uber.org/zap" + "github.com/alecthomas/chroma/lexers/m" ) var () @@ -45,12 +46,18 @@ func (c *fanControl) StartControl() { c.handler.NotifyError(err.(error)) } }() - defer close(c.fanSpeedConsumer) defer c.logger.Info("Fan control stopped") c.logger.Info("Fan control started") ticker := time.Tick(c.sampleDuration) pastFanSpeedList, newFanSpeedList := make([]int, c.processorCount), make([]int, c.processorCount) + + go func() { + for changedFanspeed := range c.fanSpeedConsumer { + newFanSpeedList[changedFanspeed.Id] = changedFanspeed.FanSpeed + } + }() + for { select { case <-ticker: @@ -58,8 +65,6 @@ func (c *fanControl) StartControl() { copy(pastFanSpeedList, newFanSpeedList) go c.applyFanspeed(pastFanSpeedList) } - case changedSpeed := <-c.fanSpeedConsumer: - newFanSpeedList[changedSpeed.Id] = changedSpeed.FanSpeed case <-c.handler.Done(): return }