Help

Re: Script exceeded execution time limit of 30 seconds because of long running fetch request

12 1
cancel
Showing results for 
Search instead for 
Did you mean: 
yiddy
4 - Data Explorer
4 - Data Explorer

In my automation script I am running a fetch request. In some cases the fetch requests takes longer than 30 seconds which results in an error. I don't really care about the fetch request result because it is a post request that is doing all it needs to however the error each time it runs is annoying.

Does anyone have any suggestions on how I can run the fetch request without waiting for a response? Or perhaps there is a way to handle the error gracefully?

4 Replies 4

Hello @yiddy,
First of all can you please share your Automation Scripting block code. Then peoples can see it and give suggestion for optimization.
Also mention API documentation link that where do you post the data.

Mostly single reauest is works fine with that 30 second threshhold. So based on your request/response data I can give you more idea about it.

Another external option is use Make.com automation where it accept data as we webhook. You need to send data from airtable to Make using that same script then it will handle everything. Using of this method you don't need to care anything just need to send data to Make.

I hope this helps to you.
👍

georgehenry667
4 - Data Explorer
4 - Data Explorer

Hi,

To handle the fetch request without causing execution time issues or errors, you can try the following:

  1. Use fetch in a non-blocking way (asynchronously):
    You can initiate the fetch request asynchronously using fetch() but not wait for the response. Use the catch block to handle any errors gracefully.

fetch(url, { method: 'POST', body: data })
.then(response => {
// You can ignore the response if not needed
})
.catch(error => {
// Log error or handle gracefully without interrupting the rest of the script
});

 

2. Set timeout in the fetch options:
You can set a timeout for your fetch request to avoid it hanging indefinitely. This way, the request will fail gracefully if it exceeds the time limit.

const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 seconds timeout

fetch(url, {
method: 'POST',
body: data,
signal: controller.signal,
})
.then(response => { /* handle response */ })
.catch(error => {
if (error.name === 'AbortError') {
console.log('Request timed out');
} else {
console.log('Other error occurred');
}
})
.finally(() => clearTimeout(timeoutId));

3. Run it in the background:
If the result of the request isn’t necessary for the script’s functionality, consider running the request in a background worker or separate process. This keeps your main script running without waiting for the fetch response.

For more insights and solutions on automation and error handling, visit sincere mechanic, where we cover common scripting issues and troubleshooting tips.

 

Thank you. I am running my script in an automation so there is no error really from the fetch request however automation scripts automatically time out after 30 seconds. I could not get setTimeout to work in an automation script either.

Hello @yiddy,
If the response and data log is not important then use 1) 2) methods suggestion from @georgehenry667.
2) Set timeout in the fetch options: This best if you know how to setup things.

Need more help then share your script.

👍