fix: add "next_scheduled_time" (#18102)

Signed-off-by: Shengwen Yu <yshengwen@vmware.com>
This commit is contained in:
Shengwen YU 2023-02-17 17:54:53 +08:00 committed by GitHub
parent 2b82f99986
commit 94dbc3fa8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -21,7 +21,9 @@ import (
"time"
"github.com/beego/beego/v2/client/orm"
"github.com/go-openapi/strfmt"
"github.com/goharbor/harbor/src/common/utils"
"github.com/goharbor/harbor/src/pkg/retention/dao"
"github.com/goharbor/harbor/src/pkg/retention/dao/models"
"github.com/goharbor/harbor/src/pkg/retention/policy"
@ -92,6 +94,12 @@ func (d *DefaultManager) GetPolicy(ctx context.Context, id int64) (*policy.Metad
return nil, err
}
p.ID = id
if p.Trigger.Kind == policy.TriggerKindSchedule {
cron, ok := p.Trigger.Settings[policy.TriggerSettingsCron]
if ok && len(cron.(string)) > 0 {
p.Trigger.Settings[policy.TriggerSettingNextScheduledTime] = strfmt.DateTime(utils.NextSchedule(cron.(string), time.Now()))
}
}
return p, nil
}

View File

@ -32,6 +32,9 @@ const (
// TriggerSettingsCron cron
TriggerSettingsCron = "cron"
// TriggerSettingNextScheduledTime next_scheduled_time
TriggerSettingNextScheduledTime = "next_scheduled_time"
// ScopeLevelProject project
ScopeLevelProject = "project"
)