Help

Simple script exceeding 30 second execution time limit

Topic Labels: Automations
614 9
cancel
Showing results for 
Search instead for 
Did you mean: 
MateuszTelega
4 - Data Explorer
4 - Data Explorer

Hi,

I have a very simple script that sends two single fields of one record via a webhook to another service. Yet I'm getting an execution error:

Script exceeded execution time limit of 30 seconds

This script was working fine for last two years and now it's throwing this type of an error once in 5-6 executions. How can I fix that?

The script:

 

console.log(`Hello, ${base.name}!`);
let inputConfig = input.config();
let response = await fetch('here_is_my_webhook_url', {
    method: 'POST',
    body: JSON.stringify(inputConfig),
    headers: {
        'Content-Type': 'application/json',
    },
});
9 Replies 9

Hmm, when you use something like Postman to ping the other service, how long does it take to respond on average?  Given that's all your code it seems possible that the other service is just taking awhile to respond sometimes

If, after you test it say, 20 times, and none of those times it takes >20 seconds to respond, then we know it's localized just to how Airtable's executing your script.  If you're not using the response at all, maybe you could remove the 'await'?  Hopefully someone else has a better idea!

 

Hi,

add this to your code:

let result=(responce.ok)? await responce.json() : responce.statusText;
console.log(result)

and then, after script timeout, look at the history - what happened?
also, what kind of data is in input.config()?

I will check this and report.

I'm sending just two variables: ID (a 3-digit number) and a specific URL.

That might be a thing. The automation runs at night, when there might be some short periods of maintenance works that could result in service unavailability.

Can you please elaborate more on what will be the consequences of removing "await"? I'm not sure if that matters, but this script is not working in any kind of loop. However, there might be some scripts trying to reach the mentioned service at the same time.

Yeah, are you able to check logs on the external service or something?
---

Removing the 'await' just makes the script run the fetch and then complete, instead of waiting for the response for the server (I'm probably butchering the explanation though and would highly recommend you check out what the 'await's doing here )

And so if you meet the following criteria then there aren't really any consequences I think:
1. You're certain the external service is operating just fine
2. You're not using the response from the service in any way or form

In this situation, you just want to avoid the error emails from Airtable's automations as everything's working just fine and you're just hitting a timeout due to some quirk with how stuff works on Airtable's side of things, does that make sense?

Thank you for claryfing this. I've made some digging and it seems that Airtable is terminating scripts after 30 seconds anyway: https://support.airtable.com/docs/run-a-script-action

Do I understand correctly that in this circumstances deleting the "await" command will not resolve the problem?

Not at all. Thing you are running is automation script, which is limited to 30 sec.
Usual script, running from extensions tab, has no such limit.
But it also has no input.config() object. You need to hardcode your values or get them from table, maybe with button usage. 

Thank you for making this clear to me. Unfortunately, this script is a part of an automation with search step and a trigger that's connected to the cell's status.

Is there any way to incorporate in the script code a loop that will try to reach the server until it's done? Something that will "reset" the execution time before it reaches the 30 sec limit.

Assuming the problem is that the Airtable automation is erroring out even though your external service receives all the data just fine and everything works, then deleting the "await" should solve the issue of the Airtable automation timing out

I'd highly suggest you do some research / talk to a developer specifically about your issue though