Skip to content

Commit

Permalink
修复规则无法禁用的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoxiangchun committed May 7, 2020
1 parent d874b52 commit cb13b22
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions pkg/monitor/models/suggestsysrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,17 @@ func (self *SSuggestSysRule) GetExtraDetails(
//after create, update Cronjob's info
func (self *SSuggestSysRule) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
self.SVirtualResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
cronman.GetCronJobManager().Remove(self.Type)
if self.Enabled.Bool() {
dur, _ := time.ParseDuration(self.Period)
cronman.GetCronJobManager().AddJobAtIntervalsWithStartRun(self.Type, dur,
suggestSysRuleDrivers[self.Type].DoSuggestSysRule, true)
}
self.updateCronjob()
}

//after update, update Cronjob's info
func (self *SSuggestSysRule) PostUpdate(
ctx context.Context, userCred mcclient.TokenCredential,
query jsonutils.JSONObject, data jsonutils.JSONObject) {
self.updateCronjob()
}

func (self *SSuggestSysRule) updateCronjob() {
cronman.GetCronJobManager().Remove(self.Type)
if self.Enabled.Bool() {
dur, _ := time.ParseDuration(self.Period)
Expand All @@ -246,7 +245,23 @@ func (self *SSuggestSysRule) PerformEnable(ctx context.Context, userCred mcclien
return nil
})
db.OpsLog.LogEvent(self, db.ACT_ENABLE, "", userCred)
self.PostUpdate(ctx, userCred, query, data)
self.updateCronjob()
}
return nil, nil
}

func (self *SSuggestSysRule) AllowPerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
return db.IsAdminAllowPerform(userCred, self, "disable")
}

func (self *SSuggestSysRule) PerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
if self.Enabled.IsTrue() {
db.Update(self, func() error {
self.Enabled = tristate.False
return nil
})
db.OpsLog.LogEvent(self, db.ACT_DISABLE, "", userCred)
self.updateCronjob()
}
return nil, nil
}
Expand Down

0 comments on commit cb13b22

Please sign in to comment.