EngErik

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

chrismccord

Creator of Phoenix

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

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

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

EngErik

@sribe My bad! We are using :timer_sleep in a very very bad way here :frowning:

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 :frowning:

I’ll adjust the code to fit the example and probably this will solve our issue :slight_smile:

Where Next?

Popular in Questions Top

New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement