Bot executes Script Trigger twice (due to timeout?)

For a quick introduction rather than posting a bunch of code, I set up a bot to run on 'adds only' for one table that runs a Apps Script function creating a bunch of rows in other tables. The particular function that is triggered times out at just under 360 seconds. Then it apparently restarts from the beginning.

The bot is supposed to trigger two additional scripts after that, which never occur due to the function in the first triggered script repeating. I have cancelled the execution of the second time the function executes in order to not create too many records.

First off, is this the designed behavior, and second what would be a potential workaround? I suspect anyone could attempt to duplicate this by just adding a JS timeOut() function in the script to see if they get the same result. I have a screenshot below showing the two executions spaced about 5 minutes apart. Do note that the second execution started automatically, I did not introduce a loop that starts the function over.

Markus_Malessa_0-1685465395472.png

 

0 5 4,044
5 REPLIES 5

The free version of App Script has a maximum execution time of 6 minutes, or 360 seconds. You'll have to account for that.

One way is the split the processing into multiple scripts. Can you do that, and call those multiple scripts from your Bot? That may be the easiest solution.
Or you can use installable triggers to trigger on execution x milliseconds after from another. You'd just have to figure out a solution to store any data/arguments that need passed between executions, like a queue of sorts or something. PropertiesService might be able to help you out there.

Are you using the 'call a script' task type?
If you don't have the 'return value' option turned on, you can turn on the 'run asynchronously' option to allow your bot process to continue without waiting for your script to finish.

As to why it is being triggered twice after failure/timeout, I'm not sure. The 'call a webhook' task type comes with these options:

Marc_Dillon_0-1685501655129.png

I feel the same options should be available for the 'call a script' task type. Who knows what the number of retries is set to...
Using a web-deployed script with a doPost() function, and triggered via webhook was the old way to call scripts from Appsheet.

 

So a couple of interesting observations:

I have implemented one bot with three tasks, each task refers to the same script file but executes different functions. Two of the three tasks are executed, however the third is not. I removed the 2nd script task to see if the 3rd had a problem, but then the 1st and 2nd(3rd) executed just fine. Any ideas if there is a limitation on how many successive script tasks can be executed?

I actually do run a hybrid Pro/Enterprise account under Appsheet, however my script execution time limit appears to be 360 seconds, whereas my regular GAS execution time limit is 30 minutes under any scripts not linked via Appsheet, so I assume the time limit is observed under Appsheet vs GAS.

Yes, I am using the call a script task. I will see about running async which I have not tried so far. In the mean time I am attempting to convert the existing script to bulk add via API vs adding individual rows with child rows. I encountered a limitation with this using the Appsheet database and setting [Row ID] values when generating my own row key values.

Any ideas if there is a limitation on how many successive script tasks can be executed?


Highly doubt it. Sounds like your 2nd execution was the one timing out, which timed out the bot. Bots also have execution time limits. The docs show only 2 minutes for a data-change bot, but I remember that being contentious in another thread.

 

whereas my regular GAS execution time limit is 30 minutes


Ahh, that is interesting. I know nothing about that, might need to ask support.

Regardless, if you have any script that is taking more than a few seconds, I think you should be running it async.

And if your script is just adding rows, I'd definitely use the API instead.

 

pocong
New Member

So the solution is to use batches, right?


Brenly

Depends what your problem is.

Top Labels in this Space