EngErik
Delaying message broadcast
Hey guys,
I have an API where i create some publications and broadcast a message for each publication that i created.
The issue is: When i create a publication, that resource will be available for users after one minute, but at this point, message is already broadcasted and user will try to acess it and gets an error.
My doubt: Is that a way to delay this message broadcast, without blocking the request sended to create a publication?
Most Liked
chrismccord
The best approach would be to publish the broadcast when the resource is available, after that one minute. What triggers the resource becoming available? Wherever that codepath is, is where you can hook in the broadcast. If it’s third-party processing, see if they support a post-back URL to your app, which you can then use to broadcast. Make sense?
sribe
??? The process which calls Task.start does not block, and I don’t see how the blocking inside of the task could possibly matter, since it’s not visible to anything.
outlog
Task.start(fn ->
:timer.sleep(60*1000)
PhoenixApp.Web.Endpoint.broadcast("channel_name", "xx_update", %{payload: %{id: 1} })
end)
but this is very hackish - you really want to broadcast directly when the publication is ready.. (as @chrismccord said..)
Last Post!
EngErik
@sribe My bad! We are using :timer_sleep in a very very bad way here ![]()
We are using it without a Task.start, so, that’s why we getting a blocking(long time waits) to return something trough publication creation API calls ![]()
I’ll adjust the code to fit the example and probably this will solve our issue ![]()
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









