pub_sub event not being broadcasted
I have this action in my resource:
And here is my pub_sub section:
I would expect that if I call
MyResource.update_images
it would broadcast the event, but this doesn't seem to be the case.
If I add this MarketplaceWeb.Endpoint.subscribe("property:#{property_id}")
to a process I will not receive the "property_updated"
event.
Before I was using the default update
action and was receiving the event normally.25 Replies
You can use this config to potentially debug and see where the issue might be:
config :ash, :pub_sub, debug?: true
I already use that, there is no debug message regarding pub_sub being broadcasted when I run that action
Interesting…
Try adding a
publish_all
for updates and see if that firesThis will work with this action:
But it will not work with the
:update_images
action
Seems like it only triggers if the update action is the default or primary 🤔That sounds pretty strange
how are you calling the action?
can I see your code interface definition?
`
And I call it here:
OHH
😆
So you should be getting a warning logged about this
about unhandled notifications
in your logs
At runtime or during compilation?
at runtime
Let me see if I can find it
Basically, notifications are meant to go out after a transaction happens, and normally this is handled by the action
but if you are starting a transaction manually, there is nothing it can do
Oh, I see
So what you need to do is this:
Btw, regarding the warning, I'm not seeing it:
🤔 interesting
I'm gonna try that, just a sec
oh, wow, you're right
We default to not showing the warning
That should change
Ah, now I see the warning
So, can I add return_notifications? directly to the
update_images
call or do I need to do that on the resource?
I tried Property.update_images!(property, changes, return_notifications?: true)
but this doesn't seem to workYou should be able to do it on the code interface call
you'll need
{_, notifications} =
actually thoughYou mean like this?
well, kind of
Repo.transactions
returns {:ok, whatever_the_transaction_returns}
So it would be {:ok, {_, notifications}}
Ahhh, I see, it returns in a tuple
Although come to think of it, I wonder if I could make a helper for this
I probably could. I'll put it on my list
for now you'd have to do it that way
Cool! Now it works great!
Thanks a lot Zach!
My pleasure 😄