Help

Re: How to add a retry to a script?

1460 1
cancel
Showing results for 
Search instead for 
Did you mean: 
christoph
6 - Interface Innovator
6 - Interface Innovator

Hello there,

a script that is running as part of an automation is failing occasionally because it is exceeding the 30 seconds limit. This is out of my control because it is calling an external API which sometimes takes a bit longer due to high load (OpenAI API). This is the error message.

Script exceeded execution time limit of 30 seconds
How can I add retries after 60 seconds or so?
 
Cheers
Christoph
 
3 Replies 3

This is tricky because scripts do not have a way of tracking how much time has while waiting for the external API to respond. So you cannot have the script abort the call just before the 30 seconds are up and set a flag for the retry. You also don't really have a way to provide a callback for the response.

You could have a {script running} checkbox field that the automation checks just before running the script. Then if the script is successful, the automation clear the checkbox. Then a formula field that checks if the {script running} checkbox is selected and compares the last modified time with NOW(). Have that formula field trigger a second automation that triggers the scripting automation again. But the trigger for this automation will have a far longer delay than you will probably like because NOW() only updates every few minutes to every few hours. Plus, using NOW() is resource intensive.

Overall, I recommend looking for a solution that involves a third party service.

Thank you for your response @kuovonne,

That is a bit surprising. Wouldn't it be possible to add a line to the script that uses the error message as a trigger for the script to run again? Something like "If the response of the script is 'Script exceeded execution time limit of 30 seconds' try again"?

 

Cheers
Christoph

If the script exceeds execution time of 30 seconds, then the scripting action fails and the entire automation run stops mid-script. Once the script hit 30 seconds, the game is over. You don't get to run addition code that triggers the script to run again. You don't get to run a followup automation action that checks if the scripting action was successful. You either need to put the check on the automation status external to the automation itself, or have a way of checking on the status of the promise before it is resolved.

There are some interesting ways of getting the status of a promise that you can try searching for. Some won't work with Airtable because they require additional libraries. Others with .race look like they have potential, but I haven't use them and cannot say for sure if they will work.

Other automation platforms have better ways of dealing with when an automation fails but Airtable has not yet built that into its automation system.