feat(notify): support db_dispatcher notify

This commit is contained in:
马鸿飞
2023-10-12 15:30:00 +08:00
parent 990307c3bf
commit 2d7766dc4c
7 changed files with 69 additions and 4 deletions
+22
View File
@@ -55,6 +55,28 @@ func init() {
Action: ActionUpdate,
})
})
db.SetCreateNotifyHook(func(ctx context.Context, userCred mcclient.TokenCredential, obj db.IModel) {
_, ok := notifyDBHookResources.Load(obj.KeywordPlural())
if !ok {
return
}
EventNotify(ctx, userCred, SEventNotifyParam{
Obj: obj,
Action: ActionCreate,
})
})
db.SetDeleteNotifyHook(func(ctx context.Context, userCred mcclient.TokenCredential, obj db.IModel) {
_, ok := notifyDBHookResources.Load(obj.KeywordPlural())
if !ok {
return
}
EventNotify(ctx, userCred, SEventNotifyParam{
Obj: obj,
Action: ActionDelete,
})
})
}
func AddNotifyDBHookResources(keywordPlurals ...string) {