Wait after server action

I want to create a server action like this:

  1. API action
  2. (wait untill API action has completed)
  3. Insert API data into database

Step 1 and 3 is no big deal, but I’m not sure how I can make the insert step “wait” untill the API action is completed. Now the insert runs faster then the API action has gathered data, so it won’t insert any data at all.

Hello Nevil,

Are these 2 separate actions, or are these steps in a same server action?

In the same server action.

I was thinking, when using a repeat, a “wait untill” doesn’t seem to be needed. Only in my particular situation I don’t need a repeat since it’s just one row of data coming from the API.

You can use the repeat step with even one record, if that’s what you want to do.

The API action should be completed before it continues to the next step, on the server nothing happens async and steps only continue when the previous was finished.

1 Like

Good to know Patrick, then I probably made a mistake somewhere :slight_smile:

Got a bit different situation now. I have a server action with an API action post, and after that one the server action gives a response with some data from our software provider. And this is fine.

But our software where we submitted the API call to, then goes to calculate some things in their backend, which takes about 30 seconds or so. But they don’t give that new calculated data back in their response of the previous mentioned API call. We basically have to do a new call for that.

I have tried to make a action scheduler which runs 30 seconds after success event with the above mentioned server action, which does work, but if I submit the first API call multiple times within that 30 seconds waiting time, it seems to only fire the action scheduler once. Is that correct or did I do something wrong? Or is there a better way to go about this? @Teodor

Hi Nevil,
So what do you need to exactly - to wait at least 30 seconds, and then call some other API/server action once or multiple times?
Also how do you know if 30seconds are always enough?

That is exactly what I need.

Usually it takes around 5-10 seconds (I can see this in the UI of the software provider), but I keep 30 seconds as a margin.

Ok, so what is the issue with the data iterator scheduler then? If you set it to run once, after 30seconds delay?

I haven’t mentioned the data iterator here, you mean the action scheduler I think?

The problem with running the action scheduler 30 seconds after the server action, is that when I submit the server action again in between those 30 seconds, it “overwrites” the waiting time of 30 seconds. Or at least that is what it seemed like.

But I have already discovered something I can use fully on the server side, a custom query with the following code:

DO sleep(30)

This makes sure the server action keeps pending/executing, and then after those 30 seconds it will run the seconds API call.

This works fine basically, but in terms of the wappler UI, I would think a ‘wait’ element would be better.

Yes’ that’s right - if it is the same action which controls the scheduler on success, it will reset.

That’s a nice idea.
I’ll check with Patrick when he’s back from his summer vacation if that can be added as a component in the Server Connect.

1 Like

Hi Everyone,

I have a similar issue and after a bunch of searching have not found an answer.

Is there any way to issue a wait / delay of x seconds as a server action without a database connection and custom DB query?

Here is my scenario, using Server Actions, I call an api #1 (backend function, processing occurs etc…this takes a few seconds to execute say 10, this response is variable 5-20 seconds max). I then call api #2, this returns a status and some values that I need for my application scenario. If I call API #2 in sequence immediately, it get a IsReadyStatus returning “false” and I get a null value.

Ideally I would like a delay or sleep call in server actions.

Is it possible to do this with a while or repeat loop?

E.G.

Repeat until API#2 Status Call returns Ready
Issue API#2 call, get value for status
If IsReadyStatus is “True”, capture data values, exit
If IsReadyStatus is “false”, wait 2 seconds and retry

I still see the need for a delay or wait function as repeating executing against API #2 IMO is similar to a ddos attack on the API.

Any thoughts and recommendations on how to solve? Thanks!