sagarmounika

sagarmounika

Updating values in loop and generate Puppeteer Pdf in loop without timeout error

Hi,

I have a list, where I have to generate a pdf for each value in the list and keep track of which pdf is getting generated to display on UI (using socket assign).

I have two issues:

  • It’s working fine for some time but after some time page is reloading and giving this error
    received timeout while communicating with server. Falling back to hard refresh for recovery
    while pdfs are getting generated in the background.
    It works fine when I remove PuppeteerPdf.Generate code

  • I am unable to update the value (current_pdf) in the loop.

     for x <- results.fetch_data do
      handle_single_item(x,socket)
      end
 def handle_single_item(value,socket)do
       // fetch_kyc is another async fn.
          result= Task.async(fn ->fetch_kyc(value,socket) end)
          awaited_result = Task.await(result, :infinity)

         //print_pdf fn is to generate pdfs

           pdf_result = Task.async(fn -> print_pdf(socket, awaited_result) end )
          Task.await(pdf_result, :infinity)  
          {: ok, socket}
 end
def print_pdf(socket,result)do
    html = Task.async(fn -> Phoenix.View.render_to_string(
    CrmUpdatedWeb.HomeView,
    "template.html", formdata: result,  socket:  socket
    ) end)
    awaited_html = Task.await(html, :infinity)
    name = :rand.uniform(256)
    socket= assign(socket, :current_pdf, name)
    // Using PuppeteerPdf to generate pdf
    result=  PuppeteerPdf.Generate.from_string(awaited_html, "../RANDOM#{name}.pdf", [print_background: true,
      timeout: 20000
    ] )
     {: no reply, socket}
   end

Thanks.

Most Liked

Hermanverschooten

Hermanverschooten

What are you doing with the PDF’s that are generated? Sending them to the browser or to disk?
I have setup something similar last week. Although I did it by adding an iframe to the page and settings its src to a regular controller action that generates the PDF. That controller action while it is generating uses PubSub to report progress to the page, once the generation is complete the zip-file with all pdfs is downloaded by the browser.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

We're in Beta

About us Mission Statement