Broadcasting pubsub update notifications only if the resource has been changed?
At the moment a broadcast is made after the action is successfully performed - even if nothing on the record actually changed.
My scenario is having a background worker that checks validity of some credentials in a loop periodically, in an action like so:
A resource with valid credentials will have
invalid: false
and that attribute won't change, but I still get a pubsub notification after each check.
It's not causing any real problems, but a) the logs are super noisy with all the extra unnecessary pubsub notifications being sent around, and b) unnecessary work is being done by the recipients of the broadcast that doesn't need to be. (eg. templates might re-render, or in my case the background worker presence is verified, and started if its not already).
Is there some way we could configure pubsub for updates to not broadcast unless something was actually updated?6 Replies
Hmm...I'm wondering if perhaps that should be the default behavior. We won't always be able to know, i.e for atomic operations though. So perhaps it should be action by action configuration
it seems like a sensible default to me, but it would definitely be a breaking change if anyone was relying on the old behaviour. i can't think of an example of when the current behaviour would be wanted though.
for atomic operations (or any case where it can't be known if something happened or not) we should probably default to sending the notification
Yeah, agreed. Which we should be able to do 👍
Come to think of it though, I think people probably are relying on this
i.e with an action like
add_comment
they are likely relying on getting the parent notification. You could monitor for a comment created, or for the add_comment
action being called.
So I think we're going to have to do this slightly differently. We could put it in the action:
or in the pub sub notifier
thoughts?ah right, if you had an update action that doesn't touch the resource itself, but uses hooks to do related stuff, you still want to know about it. that makes sense
I think configuring it in the notifier would be better
Agreed. Could you open an issue in Ash? I’ll see if I can add it this week 🙂
GitHub
proposal: Allow configuring pubsub notifiers for update actions to ...
Is your feature request related to a problem? Please describe. (See https://ash-hq.org/forum/support/1126780995845230632 for some context) At the moment, pubsub notifiers will always broadcast noti...