Loading bar for long-running server actions

I have some very long running server actions (some take a few minutes). This long time is not a mistake, there is just a lot of data to get.

What I want is a percentage loading bar while this server action runs, counting up from zero to 100%. This might be difficult as there might not be an exact way to predict how long the server action will run. But I’ve seen this in other applications before, so it must be technically possible.

Also, let’s say it’s at 60% loaded and I refresh the page, the loading bar should appear again where it left off. So the already running server action should be visible again at 60% (to all users on that page). Once it’s running, it cannot run a second time by anyone. After it’s done, it can be run again.

This might be stretching Wappler in what is capable, but I’m very curious to know if (and how) this can be done!

Hello Nevil,

Due to the nature of how server actions are served it’s not possible to determine the content length. We are using transfer-encoding=chuncked which is great for buffering especially for large data sources, but this method returns the content length as undefined.

Learn more here:
https://www.httpwatch.com/httpgallery/chunked

So for now it’s not possible to have precise percentage values for the data loading/processing. You can, however check when the status is == executing, so you can show some message or loading animation.

Well maybe the new App Connect Flow will help you.

If you can split your server action to smaller separate server actions, you can call them in a flow and report progress from the flow after each step.

As flows run client side you can access all the page data and build and update progress bars as you wish.

3 Likes

I’m wondering if something like this would work. Note: I never tried it.

In the server action, set a variable (let’s call it Progress) to zero and click on the output box to make it visible to the client. We’ll use that variable to feed the progress bar widget.

During the long server action you have, increase the value of Progress as you go by. Maybe you can do this based on the number of records to be processed (the query.count() will tell you that) if you have a repeat instruction, or maybe you simply increment it based on the step that has just been completed. By the latter I mean that if your sever action has 10 steps, you would increment the Progress variable by 0.1 at the end of each.
It won’t be a precise indicator, but from a user perspective, it may be enough.

If the theory works, the progress bar should reflect the value of Progress as your server action progresses in its execution.

Hope this helps,

Alex

1 Like

Interesting! Will try this