mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
修复规则无法禁用的问题
This commit is contained in:
committed by
zhaoxiangchun
parent
c106bdc24c
commit
829c6c65fc
@@ -222,18 +222,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)
|
||||
@@ -254,7 +253,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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user