Forum Academy Marketplace Showcase Pricing Features

Backend Workflows problem

I am running a series of 3 backend workflows that work on a single record (Employee). I call them from a workflow on the page using the “Schedule API Workflow on a list” action. They need to run sequentially as each is dependent on the prior completing. The list is a query of all Employees impacted by the change in the page workflow. The record I am sending is This Employee.

The problem I am having is that it appears that the first workflow is not completing the entire list. I assume that if you run the workflows with current date/time they will all run in parallel. What about when you need the first workflow to complete before the next one runs? I tried adding a few seconds delay but that didn’t help. Thanks in advance.

Is there an OnComplete feature in Bubble

A common approach would be to chain each workflow together in a single workflow, and make each workflow return something. Would that work maybe?

I guess…there are times where I need just one of the workflows so I was hoping to separate them, but it wouldnt be that bad if I duplicate them. OnComplete or some type of wait feature would be awesome. thanks

Instead of ‘schedule workflow on a list’ make the API workflow itself a list.

You do this by ticking ‘is list/array’ on the parameter
image

Then use the action ‘make changes to a list of things’. When you are scheduling the api workflow choose ‘schedule api workflow’ and feed in the list.

Doing it this way makes the workflow complete the list in one hit. Scheduling on a list makes the workflow loop through the list and only does one record every X seconds.

If you have a sequence of these, make each step a separate API workflow (with the list ticked) and use ‘as a result of previous step’ to feed in the value of the list.

One caveat - I think it depends on your list size and you’d have to see how many records is safe to have on the list before you risk timing out. I’ve never needed to do this on very large lists so I’ve not researched this side of it.

4 Likes

Thanks Natasha…that was very helpful. It works. Much appreciated.

Is this something that you have from the page scheduling backend workflow 1 (BEW1), and then after BEW1 finishes you want BEW2 to run and after that finishes run BEW3? And you want for each BEW1, 2 and 3 to perform some processing of data on the employees you have in the list after the query on the page?

Not exactly that, but in the backend workflows you have the ‘custom workflow’ trigger available, which works differently than other workflows in that all actions in it will complete before another step in a series of actions you trigger the custom workflow in.

For example a 5 step series of actions. Step 1 triggers and doesn’t necessarily complete before step 2 triggers which doesn’t necessarily complete before step 3 triggers (but step 3 is a custom workflow) (imagine the custom workflow has 2 actions) the two actions in the custom workflow will trigger and complete before Step 4 is triggered.

I use this in my apps when I need to refresh some API credentials before running the API calls in the backend to ensure my API credentials are refreshed and saved properly before the API call is attempted.

Do you know how you will determine if all 3 are needed or not? Some kind of condition that would make it true that you don’t need BEW2 or 3 for example?

Bubble gives you 5 minutes to complete a workflow before it times out…most important variable maybe on the amount of data being processed on the list rather than the length of the list.

From my perspective, the best approach when working with lists in backend workflows is to create recursive backend workflows, so that you are processing a single list item at a time, and therefor have 5 minutes to process the data of that single item, before looping back and processing the next item in the list.

The amount of time it would take for running the backend workflow recursively versus processing the entire list at one shot I believe would be the same, but with recursive approach, you are far less likely to run the risk of timing out.

When I first ran into an issue with backend workflow running into issues processing a list, a Bubble engineer recommended I use a recursive backend workflow instead and I’ve never used any other approach since.

Ahh this is good to know!

Yes, :slight_smile: @equibodyapp I saw that “5 minutes” and thought “ahh that explains a lot”. I went looking for something to corroborate that little gem @boston85719 of info and found this
https://bubblegroup.gitbooks.io/bubble-manual/content/building-workflows/general-principles.html

2 Likes

This topic was automatically closed after 70 days. New replies are no longer allowed.