wildfalcon
Commanded Projections - how do I notify my system when ready
I’m writing an ES system with commanded.
I can dispatch commands, and they are getting handled, events are being published, and I have a read model being created (using commanded.ecto.projections).
Where i am struggling is in deciding when / how to tell other parts of my system that the read model is updated. In my example, it’s a LiveView, but it could be any other part of the system.
I can broadcast a Pub/Sub event in the project method, like this:
project(%BudgetCreated{} = event, fn multi ->
multi
|> Ecto.Multi.insert(:budget, %Budget{
uuid: event.budget_id,
name: event.name
})
# I can broadcast the event to the live view here
multi
end)
But that may result in the LiveView responding to the Pub/Sub message before the db is finished updating, which would prevent the user from seeing the update.
What I would like to do is wait till the read model is finished writing to the db and then send broadcast the pub/sub message
Is there a best practice for doing this?
Marked As Solved
wildfalcon
Somewhat embarrassingly, I realised that despite staring at the docs for a while, I had missed the after_update/3 callback, which does exactly what I was looking for
https://hexdocs.pm/commanded_ecto_projections/Commanded.Projections.Ecto.html#c:after_update/3
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








