FlowApi: running in foreground vs background

Ethan Dy Tioco1
Tera Expert

Hi all,

 

I have a Flow Designer flow where the trigger has:
- Trigger = Created or Updated
- Run Trigger = Only if not currently running
- Where to run the flow = Run flow in background (default)

 

When I look at Create Code Snippet, I see that the server script has two options to run in the foreground or background. Something like:

1) sn_fd.FlowAPI.getRunner().flow('flow_name').inBackground().withInputs(inputs).run();
2) sn_fd.FlowAPI.getRunner().flow('flow_name').inForeground().withInputs(inputs).run();

 

By default, inBackground() is commented out, so it looks like it wants me to use inForeground().

 

My question is this:

Would inForeground() interfere with the trigger conditions of "Where to run the flow = Run flow in background (default)"?

I want to call FlowAPI from a daily scheduled job. If the scheduled job loops through 30 or so records and calls FlowAPI to execute the flow for each record, would inForeground() cause issues like taking a long time to run?

FlowAPI run in foreground is default.png

 

Thanks in advance for the help 🙂

2 REPLIES 2

DrewW
Mega Sage
Mega Sage

Like the comment says one is for synchronous and the other is for asynchronous.  So my understanding is if you use the inForeground your code will wait for the flow to run and finish before moving on to the next line.  inBackground causes the code to move on immediately to the next line and the flow will execute on its own and not hold things up.

 

Gotcha. I'm expecting a single flow execution to take days-weeks to complete (it has approval steps, so it's up to how fast the approver gets to it), so if I expect my scheduled job to trigger 30 flow executions in a few seconds, looks like inForeground() is not the way to go.