mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-27 04:35:16 +01:00
Merge pull request #2865 from vmware/fix_issue_#2680
Fix config change watching issue
This commit is contained in:
commit
8612a9ac84
@ -2,7 +2,6 @@ package notifier
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"github.com/vmware/harbor/src/common/models"
|
"github.com/vmware/harbor/src/common/models"
|
||||||
"github.com/vmware/harbor/src/common/utils"
|
"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 t, yes := policyCfg.Parm["daily_time"]; yes {
|
||||||
if reflect.TypeOf(t).Kind() == reflect.Int {
|
if dt, success := t.(float64); success {
|
||||||
policyNotification.DailyTime = (int64)(t.(int))
|
policyNotification.DailyTime = (int64)(dt)
|
||||||
|
} else {
|
||||||
|
return errors.New("Invalid daily_time type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,6 +200,8 @@ func (nw *NotificationWatcher) Notify(notification Notification) error {
|
|||||||
if err := hd.Handle(notification.Value); err != nil {
|
if err := hd.Handle(notification.Value); err != nil {
|
||||||
//Currently, we just log the error
|
//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())
|
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)
|
}(h, handlerChan)
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/vmware/harbor/src/common/scheduler/task"
|
"github.com/vmware/harbor/src/common/scheduler/task"
|
||||||
|
"github.com/vmware/harbor/src/common/utils/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
//AlternatePolicyConfiguration store the related configurations for alternate policy.
|
//AlternatePolicyConfiguration store the related configurations for alternate policy.
|
||||||
@ -125,6 +126,7 @@ func (alp *AlternatePolicy) Evaluate() (<-chan bool, error) {
|
|||||||
}
|
}
|
||||||
if diff > 0 {
|
if diff > 0 {
|
||||||
//Wait for a while.
|
//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 {
|
select {
|
||||||
case <-time.After(time.Duration(diff) * time.Second):
|
case <-time.After(time.Duration(diff) * time.Second):
|
||||||
case <-alp.terminator:
|
case <-alp.terminator:
|
||||||
|
@ -70,6 +70,7 @@ func (wc *Watcher) Start() {
|
|||||||
select {
|
select {
|
||||||
case <-evalChan:
|
case <-evalChan:
|
||||||
{
|
{
|
||||||
|
log.Infof("Receive evaluation signal from policy '%s'\n", pl.Name())
|
||||||
//Start to run the attached tasks.
|
//Start to run the attached tasks.
|
||||||
for _, t := range pl.Tasks() {
|
for _, t := range pl.Tasks() {
|
||||||
go func(tk task.Task) {
|
go func(tk task.Task) {
|
||||||
|
Loading…
Reference in New Issue
Block a user