How to wait for a long-running Backend Workflow and return a file (Avoiding Frontend Timeouts)?

Hey guys!

I have a scenario where I generate a complex PDF using an external API (DocMaker). The JSON payload is massive, and the generation process takes some time.

The Problem: I must run this logic in a Backend Workflow because if I try to run it directly from the frontend (Action in Page), I frequently hit browser timeout errors before the file is ready. The Backend environment has higher timeout limits and handles this heavy processing much better.

The Goal: I need the user to click “Generate”, have the frontend wait for this long-running Backend process to finish, and then get the file URL back to trigger a download.

My Question: Since “Schedule API Workflow” is asynchronous (fire and forget), is there a plugin or a pattern to call a Backend Workflow “synchronously” from the page?

Basically, I need the frontend to “hang tight” while the backend does the heavy lifting, and only proceed when the file is actually returned.

I know about the “API Connector to self” workaround, but is there a cleaner way or a specific plugin for this “Long Polling / Synchronous Wait” scenario?

Thanks!

Hi

  • API connector to self is a clean approach if you need to return data from backend wf to front
  • another way,
    • create a datatype with your Generation Logs and user + status field
    • button generation is clicked, create a Log
      • choose a group/popup where to display this Log
    • pass this as a parameter in your backend wf
      • make change to the Log’s status: initiated → started → success/error
      • update front end according to the group/popup Log’s status

Also if the generation take very long, you maybe want to chunk generation

  • then you create a sub datatype Generation Log Chunk with a Log field, chunk # out of # and it’s own status field
  • with this you would be able to know and display
    • % generated
    • where the wf happenned to fail when there is an error and resume

Hope this would help!

Hi @ativosinfoeduc, I encountered a similar issue when building DocuPotion, so thought my two cents might be useful.

I ran into a problem with the 30-second timeout that Bubble has on all plugin server-side actions (the DocuPotion plugin has a ‘Create PDF’ action that users run in the frontend).

The 30-second limit was rarely hit, but occasionally a user would want to generate a very complex PDF (long repeating groups, multiple nested repeating groups, very data-heavy etc.) and it would trigger the error.

The solution I came up with was to turn the ‘Create PDF’ action into an asynchronous action and ask the user to setup a backend workflow that ‘processes’ the PDF on the backend.

So the PDF generation now works as follows:

  • User sets up backend workflow to process PDF (i.e. attach it to a ‘thing’ in your database)
  • User triggers ‘Create PDF’ action on frontend and provides callback URL
  • PDF is generated by DocuPotion API
  • DocuPotion calls the backend workflow to let user’s app know the PDF has been generated

Most relevant for you:

  • The user adds the ‘Trigger a custom event when data changes’ event to the frontend workflow
  • The custom event downloads the PDF in the users browser

This means that when the backend workflow processes the PDF, it downloads automatically in the frontend.

This section of the DocuPotion docs may be useful for more detail on this.

Hope that helps!

Alex

2 Likes

Thank you very much, I will look into it.

Thank you very much, I will take a look, I’ll let you know if anything comes up.

1 Like

Is this the DocMaker you are using? The API and also the bubble plugin(s) has a section for webhook, which you can direct to a backend API workflow endpoint.

1 Like

Lately I’ve been using CraftMyPDF to generate PDFs. I’ll check their documentation to see if I can find something similar.

Look for the webhook option in Integrations > REST API, create-async