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:
@@ -72,6 +72,14 @@ func CreateAccount(cmd *m.CreateAccountCommand) error {
|
||||
_, err := sess.Insert(&user)
|
||||
cmd.Result = account
|
||||
|
||||
// silently ignore failures to publish events.
|
||||
_ = bus.Publish(&m.Notification{
|
||||
EventType: "account.create",
|
||||
Timestamp: account.Created,
|
||||
Priority: m.PRIO_INFO,
|
||||
Payload: account,
|
||||
})
|
||||
|
||||
return err
|
||||
})
|
||||
}
|
||||
@@ -85,6 +93,16 @@ func UpdateAccount(cmd *m.UpdateAccountCommand) error {
|
||||
}
|
||||
|
||||
_, err := sess.Id(cmd.AccountId).Update(&account)
|
||||
if err == nil {
|
||||
// silently ignore failures to publish events.
|
||||
account.Id = cmd.AccountId
|
||||
_ = bus.Publish(&m.Notification{
|
||||
EventType: "account.update",
|
||||
Timestamp: account.Updated,
|
||||
Priority: m.PRIO_INFO,
|
||||
Payload: account,
|
||||
})
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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