Add inital implementation of Notification events.
If notifications are enabled in the config, Adds a eventHandler
accepting Notification{} payloads to the internal Bus. The
eventHandler then marshals the payload into json and sends it
to a rabbitmq topic exchange using the
Notification.Priority+Noticiation.EventType as the routing key.
eg. INFO.account.created
Currently, notifications are only being emitted for
INFO.account.created
INFO.account.updated
INFO.user.created
INFO.user.updated
This commit is contained in:
@@ -95,6 +95,12 @@ func CreateUser(cmd *m.CreateUserCommand) error {
|
||||
_, err = sess.Insert(&accountUser)
|
||||
|
||||
cmd.Result = user
|
||||
_ = bus.Publish(&m.Notification{
|
||||
EventType: "user.create",
|
||||
Timestamp: user.Created,
|
||||
Priority: m.PRIO_INFO,
|
||||
Payload: user,
|
||||
})
|
||||
return err
|
||||
})
|
||||
}
|
||||
@@ -135,6 +141,16 @@ func UpdateUser(cmd *m.UpdateUserCommand) error {
|
||||
}
|
||||
|
||||
_, err := sess.Id(cmd.UserId).Update(&user)
|
||||
if err == nil {
|
||||
// silently ignore failures to publish events.
|
||||
user.Id = cmd.UserId
|
||||
_ = bus.Publish(&m.Notification{
|
||||
EventType: "user.update",
|
||||
Timestamp: user.Updated,
|
||||
Priority: m.PRIO_INFO,
|
||||
Payload: user,
|
||||
})
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user