wildfalcon
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?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
wildfalcon
Somewhat embarrassingly, I realised that despite staring at the docs for a while, I had missed the
after_update/3callback, which does exactly what I was looking forhttps://hexdocs.pm/commanded_ecto_projections/Commanded.Projections.Ecto.html#c:after_update/3
linusdm
Formulating a good question, is often half the solution.
Welcome to the forum!