Ash FrameworkAF
Ash Framework3y ago
11 replies
Rebecca Le

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:

    update :update_credential_validity do
      change set_attribute(:invalid, true)
      change set_attribute(:invalid, false), where: [{Vendor.CredentialValidation, []}]
    end


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?
Was this page helpful?