Queue backend workflow so they don't 'overlap'?

Hi!
I am using backend workflows but at the moment, I have a problem because if two or more of these backend workflows are triggered at the same time (by the same user or not), the calculations done in the workflows are all mixed up, and it messes with my app. Basically, what I need is for each workflow to be finished before another one of the same workflow is triggered… Has anyone encountered that problem ? Do you see a way around that ?
Thank you very much,
Arthur

1 Like

Any update ? I have the same issue here

Schedule the last backend workflow at the end of the first one.

How did you know that ?
The workflow is launch with a button in front end

Yea so schedule only the one you want to run first, and then from that backend workflow schedule the other one you want to run after

Tks
In my case. Some push a button to do thing and start the workflow and if another user push the same button on another browser the 1st workflow stop and the second iteration start. I’ve no ways to know if the same workflow is allready started for someone else

You’ll need to create a queue system to ensure only 1 iteration of the workflow is ever taking place.

There are various ways to go about it, depending on the complexity and needs of the specific use case (sometime you’ll even need to have a queue to join the queue…).

Create a datatype of Queue Item containing all the required data for the workflow run.

Whenever the relevant action takes place (such as a User clicking a button), create a new queue item.

Any time a new queue item is created trigger the main workflow to run… but ONLY if there are no other queue items.

In the main workflow, at the end of each run delete the queue item (or mark is as complete) and trigger the workflow to run on the next queue item.

1 Like

thk I’ll try to see if it’s possible but it can be hard. Sometimes 5 workflows are chained after a single action and a workflow can be called from different actions so this means may be one queue per workflow…

You only need to queue the beginning of the process, no matter how may workflows are chained together. Just restrict the first one from starting if there is already one in the process.

Tks
I’ve splitted the workflows because sometimes some actions don’t need the whole process and call directly the last workflow. So I need to create a big workflow with lots of exceptions to have my own queue

It might be simpler to always just send things into the first workflow, and then skip them if they’re are not needed and progress them to the next step.

That way you’ll only need one queue, and don’t run the risk of running various stages of the workflow at multiple times.

Hi @adamhholmes @saloon-esquiver0t

Let me tell you my case. There are events in my app and a maximum of 5 people can attend an event. Registered data is generated for each participation. I have a join event button. There is a condition in the button’s condition that counts the Registered data of the event and ensures that it runs if it is less than 5.

Let the Registered number of the event be 4. When two different users click on the same button at the same time from two different computers, the search in the button condition gives the result as 4 for both of them, and both users participate in the event and the number of participants in the event becomes 6.

@adamhholmes I liked your idea and started implementing it. I moved the event participation workflow to the backend. I created a data type named Queue. As you said, when I set a condition for the Backend API to be triggered if there is no other Queue data, I feel that 2 cases will occur:

1- Search in the condition sends a Queue item other than itself to two users and the Backend API does not work for both users.

2- Search in the condition does not return any Queue item other than itself for two users, and the Backend API works for both users.

I would be grateful if anyone can help.

Pushing a button at the same time (millisecond) is low probability.
Do something like when the user click a btn it change immediately a variable in the DB SO when the others user push the button the Wf loop until it can do is action

1 Like