I’m working on a project in Bubble and need some help with handling a loading spinner while multiple backend workflows are running.
What I’m Trying to Achieve
I have a button that triggers a backend workflow (let’s call it Workflow A). This workflow then triggers four additional recursive (looping) backend workflows (Workflows B, C, D, and E). Each of these recursive workflows loops through a list from a JSON and creates items in the database.
I want to display a loading spinner while all of these recursive workflows are running and then hide the spinner once everything has completed.
I tried implementing a solution where I create a database entry backend_workflow_log that is set to complete when a workflow finishes. However, this approach doesn’t work as expected because:
It will create the backend_workflow_log on the first loop of the recursive workflows, rather than wait for the final one to complete.
Since the workflows run asynchronously, I don’t have a clear way to track when all of them have finished.
Here’s a simplified version of what is happening:
Workflow A takes a JSON file and generates four separate lists.
Workflows B–E each process one of these lists, looping through their items and creating database entries for each iteration.
It would be great if there is a way of doing this by creating things in the database, like backend_workflow_log. But I’m open to suggestions, Thanks!
If you know beforehand how many items will be created, you can show the spinner on button click and hide it once the created items matches the number you already know
basically you have to build the logic to track the completions
one way you could do it
1 - schedule workflow to “initialize” process this then logs the total count and starts the repeater
2 - repeat to create/edit each thing
3 - count up on each completion
4 - force doing the items one after the other instead of concurrently
5 - have a progress bar on the front end for the user to visualize (requires saving the count and total somewhere)
it there are multiple lists to process then the only way to do it is to force process them one after the other instead of concurrently.
I got this working, similar to what @mitchbaylis suggested although I think there are probably more efficient methods out there. Here’s how I approached it:
Create a backend_workflow_log entry when the user clicks the button that starts the workflows. This is immediately in the normal button workflow so the user immediately sees the spinner.
Determine the total count of items in each list once I receive the response from the API (which provides the lists to be processed). At this point, I update the corresponding backend_workflow_log entry with the total count of items for that specific list. Since I have four lists, I create four backend_workflow_log entries.
Ensure all lists are accounted for by chaining Do a search for expressions, so the spinner only disappears once all backend_workflow_log entries have reached completion (i.e., current_count = total_count for each list).
Potential Improvement Needed
This approach works, but since I have four lists to process, I will end up with eight Do a search for expressions in a row in the spinner show/hide Conditionals. It feels inefficient, and I’d love to know if anyone has a cleaner way to achieve the same result without so many searches.
Or, maybe this is completely acceptable and efficient, which I’d also love to know