EngErik

EngErik

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?

Showing Posts 1 to 5

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?

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..)

EngErik

EngErik OP

Hey @chrismccord thanks for you time!

Your approach it’s the best way to solve the problem, but unfortunately, it’s a third party service that can’t provide me a callback or something like that.
Actually I use the approach that @outlog shared here, but with this kind of solution, whole process still blocking until the sleeps time end. :frowning:

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.

EngErik

EngErik OP

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

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews