Forum Academy Marketplace Showcase Pricing Features

Not obvious behavior in the workflow with database operations

I can not understand the logic.
I have a simple page with three elements on it (Checkbox, Button and Alert):

And one workflow:

At the first step I clean up database by deleting all records with simple condition:

At the second step I create new record with Message text in the database only when Checkbox is checked:

At the third step I show the Alert with the message from the database only when I have at least one record in the database with the message:

That’s it.

During the running the behavior is strange.

Steps to reproduce:

  1. Opt in Checkbox
  2. Click Button Start
  3. See the expected result:
  4. Opt out Checkbox
  5. Click Button Start
  6. See unexpected result:

In the real application I have more complicated workflow and it does not work as I expect as well. So, I have to use database, not element’s status or something else, because the “message text” should be persistent (stored in the database).
But first, I must deal with this example. Who can help?

Hey @stavvit :slight_smile: Can you share a link to the example?

@stavvit, the 3 actions in your workflow don’t necessarily get processed in that order within bubble. I know the UI makes it look that way, but they process the actions in parallel as much as possible (which is much better for performance reasons).

Note - there’s 1 way t o override them all running in parallel. Here’s how it work: if action #2 used “results of step #1” then it’ll wait to run action 2 until after action 1 completes. Otherwise, they’ll run in parallel.

This could be the problem you’re seeing.


@sridharan.s, I suspected it :slight_smile:, and even thought how to use the result of the previous step (it didn’t help a lot). It’s good to know that actions are processing in parallel. Thank you! Also it might be useful to have something like Step 1 is processed in the condition, or maybe setting for the workflow (run sequentially or in parallel).
It seems that not only actions can be processes in parallel, but even searches in one action. That’s why one search returns one result and the second inside the same action (with the same searching condition) returns another result. It makes not a trivial task to design the workflow.
Or I have to use more workflows that starts with “Do when condition is true” event? Is this the recommended approach?

@fayewatson, I created a copy in the public application, because the original application is private. Please, you can play with it:
I added a condition Result of step 2 is not empty. Try to click on the checkbox and then on the Start button. Repeat this action a few times.

There’s also more mechanisms at work to be aware of:

The workflow is run on the server and on the client, with certain actions running on just either server or client. Sometimes a server operation waits for data from the client, like when it should run only if the checkbox is checked. The alert action runs on the client and typically doesn’t wait for server operations like storing data to be completed.

The database is cached locally in the browser, including changes, so you can store something and it will seem to have one value, even if the server hasn’t yet been updated with the value.

Some “dynamic data” is reactive, which means its value and anything that uses its value gets updated when it is changed. This change is signalled by the server to the client, in an asynchronous manner, i.e. at a timing possibly different to the workflow actions.

1 Like

Yeah, this is not going to work too well I don’t think. It is taking several seconds for the delete to complete.

You can sort of make it work by splitting the workflow in two. The button does a delete. Another workflow runs every second to pick up when the message count <= 0.

But it is really slow to respond. And if you put debug breaks in your can hang the whole app quite easily :frowning:

Might be worth raising a bug, but in the meantime can you think of another way to do what you want to do ?

I have no another way, only trying to find another design. After discovering of some peculiarity it’s easier to do. Thanks, @mishav. I’m not sure it’s a bug, if it’s inside the architecture it will be hard to change.

Another thing that there are a lot of such workflows in my application, that was built based on my thinking about the structural approach. Now I understand that I have to rewrite it based on the asynchronous approach. It can double or even triple the number of workflows and makes it harder to manage.