fedora-infra/fedmsg

Add a built-in "event hook" for sending messages based on app events

Opened this issue · 0 comments

@jeremycline wrote a useful feature for Bodhi where he queued up fedmsgs that the application wanted to send until the database commit was issued. Once the commit completes, Bodhi then issues the actual calls to fedmsg that send the messages.

I think we could abstract that idea and add a feature into fedmsg that does some of this pattern so all apps can benefit from the pattern. It would be necessary for fedmsg to provide some way for the app to register an event handler (such as a database commit in the case of Bodhi, but we'd want it to be more generic I'd think), and some way for fedmsg to hold messages that the app wants to send until the event fires.

Idea: it could be cool if the API for fedmsg to hold messages until the event was just the same API that is used to send messages. Whether the messages get immediately sent or held waiting for the event would depend on whether an event listener was registered with fedmsg or not. This could be cool because it would make it pretty easy for existing apps to adopt this new pattern - they'd just need to call the event registration API and bam!

The code in Bodhi that does this is here: https://github.com/fedora-infra/bodhi/blob/2.9.0/bodhi/server/notifications.py#L55-L123