Rebecca Le
AEAsh Elixir
•Created by Rebecca Le on 7/7/2023 in #support
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?12 replies
AEAsh Elixir
•Created by Rebecca Le on 6/12/2023 in #support
Possible to skip validation for an action? (or best practices for working with external credentials)
My app has a resource called
Vendor
for interacting with external vendors, so we store user credentials for those vendors encrypted in the resource. I've now added a validation when creating vendors, that validates that the credentials are actually valid (by talking to the external API). This works great!
However, I have a test suite that generates lots of Vendor resources in the course of testing things, and 99% of them don't use valid credentials (nor should they!) so now all the tests are failing due to this new validation.
I can see a couple of options:
* In my test functions, skip validation when calling eg. Vendor.create(data)
. This would be the easiest way, but I can't see any way in Ash to do it? (I thought there might be a nice validate?: false
opt like there's a authorize?: false
opt but there isn't)
* Use Mimic (https://github.com/edgurgel/mimic) (already used in the app) to globally stub out the new validation module, to bypass it. I can foresee running into issues when I want to actually test the validation though - I'd have to muck around with unstubbing/restubbing and I'm not sure if Mimic even supports it.
* Create a new action in my resource that is the same as the create
action but doesn't include the extra validation. This would be my least favorite option.
* Actually my least favorite option (but still an option) would be to use valid credentials to test accounts in all of the tests, but I'm not even considering doing this.
Have I missed something in the Ash docs on how to skip validations, or how would other people approach doing this?25 replies