feat(notify): add Action sync_create, sync_update, sync_delete

This commit is contained in:
rainzm
2021-10-26 10:50:12 +08:00
parent a7d54f8044
commit e5cefa54f5
37 changed files with 449 additions and 29 deletions
+4
View File
@@ -58,6 +58,10 @@ var (
ActionSyncStatus = api.ActionSyncStatus
ActionPendingDelete = api.ActionPendingDelete
ActionSyncCreate = api.ActionSyncCreate
ActionSyncUpdate = api.ActionSyncUpdate
ActionSyncDelete = api.ActionSyncDelete
)
type SEvent struct {
+14 -9
View File
@@ -249,16 +249,21 @@ func (t *eventTask) Run() {
}
func EventNotify(ctx context.Context, userCred mcclient.TokenCredential, ep SEventNotifyParam) {
ret, err := db.FetchCustomizeColumns(ep.Obj.GetModelManager(), ctx, userCred, jsonutils.NewDict(), []interface{}{ep.Obj}, stringutils2.SSortedStrings{}, false)
if err != nil {
log.Errorf("unable to FetchCustomizeColumns: %v", err)
return
var objDetails *jsonutils.JSONDict
if ep.Action == ActionDelete || ep.Action == ActionSyncDelete {
objDetails = jsonutils.Marshal(ep.Obj).(*jsonutils.JSONDict)
} else {
ret, err := db.FetchCustomizeColumns(ep.Obj.GetModelManager(), ctx, userCred, jsonutils.NewDict(), []interface{}{ep.Obj}, stringutils2.SSortedStrings{}, false)
if err != nil {
log.Errorf("unable to FetchCustomizeColumns: %v", err)
return
}
if len(ret) == 0 {
log.Errorf("unable to FetchCustomizeColumns: details of model %q is empty", ep.Obj.GetId())
return
}
objDetails = ret[0]
}
if len(ret) == 0 {
log.Errorf("unable to FetchCustomizeColumns: details of model %q is empty", ep.Obj.GetId())
return
}
objDetails := ret[0]
if ep.ObjDetailsDecorator != nil {
ep.ObjDetailsDecorator(ctx, objDetails)
}