From 7c2699953d6ebfddae31b1bcb3d175984f744dba Mon Sep 17 00:00:00 2001 From: Steven Zou Date: Tue, 25 Jul 2017 19:47:05 +0800 Subject: [PATCH] Fix config change watching issue --- src/common/notifier/config_watcher.go | 7 ++++--- src/common/notifier/notifier.go | 2 ++ src/common/scheduler/policy/alternate_policy.go | 2 ++ src/common/scheduler/watcher.go | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common/notifier/config_watcher.go b/src/common/notifier/config_watcher.go index bd86ef231..8eab3b88e 100644 --- a/src/common/notifier/config_watcher.go +++ b/src/common/notifier/config_watcher.go @@ -2,7 +2,6 @@ package notifier import ( "errors" - "reflect" "github.com/vmware/harbor/src/common/models" "github.com/vmware/harbor/src/common/utils" @@ -27,8 +26,10 @@ func WatchConfigChanges(cfg map[string]interface{}) error { } if t, yes := policyCfg.Parm["daily_time"]; yes { - if reflect.TypeOf(t).Kind() == reflect.Int { - policyNotification.DailyTime = (int64)(t.(int)) + if dt, success := t.(float64); success { + policyNotification.DailyTime = (int64)(dt) + } else { + return errors.New("Invalid daily_time type") } } diff --git a/src/common/notifier/notifier.go b/src/common/notifier/notifier.go index f93df9462..d68b9a997 100644 --- a/src/common/notifier/notifier.go +++ b/src/common/notifier/notifier.go @@ -200,6 +200,8 @@ func (nw *NotificationWatcher) Notify(notification Notification) error { if err := hd.Handle(notification.Value); err != nil { //Currently, we just log the error log.Errorf("Error occurred when triggerring handler %s of topic %s: %s\n", reflect.TypeOf(hd).String(), notification.Topic, err.Error()) + } else { + log.Infof("Handle notification with topic '%s': %#v\n", notification.Topic, notification.Value) } }() }(h, handlerChan) diff --git a/src/common/scheduler/policy/alternate_policy.go b/src/common/scheduler/policy/alternate_policy.go index 8d6ac3859..d57a103b4 100644 --- a/src/common/scheduler/policy/alternate_policy.go +++ b/src/common/scheduler/policy/alternate_policy.go @@ -5,6 +5,7 @@ import ( "time" "github.com/vmware/harbor/src/common/scheduler/task" + "github.com/vmware/harbor/src/common/utils/log" ) //AlternatePolicyConfiguration store the related configurations for alternate policy. @@ -125,6 +126,7 @@ func (alp *AlternatePolicy) Evaluate() (<-chan bool, error) { } if diff > 0 { //Wait for a while. + log.Infof("Waiting for %d seconds after comparing offset %d and utc time %d\n", diff, alp.config.OffsetTime, utcTime) select { case <-time.After(time.Duration(diff) * time.Second): case <-alp.terminator: diff --git a/src/common/scheduler/watcher.go b/src/common/scheduler/watcher.go index 9827ab37c..23067dab5 100644 --- a/src/common/scheduler/watcher.go +++ b/src/common/scheduler/watcher.go @@ -70,6 +70,7 @@ func (wc *Watcher) Start() { select { case <-evalChan: { + log.Infof("Receive evaluation signal from policy '%s'\n", pl.Name()) //Start to run the attached tasks. for _, t := range pl.Tasks() { go func(tk task.Task) {