简体   繁体   中英

How comes my script fails to run while executed by a trigger but is successful when executed manually?

I'm not sure if I have encountered with a bug or is just me not fully understanding how triggers work, probably the second one :D.

I have a google apps script that collects information through a series of requests to our CRM's API and puts it on a Google Docs Spreadsheet, the script takes a while to run, however, it runs successfully (I run it manually every morning, takes about 3 minutes). But when I try to automate that task, I get an error message saying my script exceeded its execution time limit.

I tried setting up my triggers manually, creating them within the script, breaking down my script reducing the number of API requests (taking less then a minute to execute) and execute it several times so I get the whole information. Every single time I get the same error message.

Am I missing something here? Any help will be much appreciated!

Edit: The mail I received has this error message: "Exceeded maximum execution time".

Edit2: I was able to fix this (party). I came across the answer for this question Exceeded maximum execution time in Google Apps Script and worked like a charm.

There are some limits to Google Apps Scripts that you must keep in mind: see Quotas .

It is possible that you are exceeding your total runtime for Triggers. There is also the shorter individual execution time limits on Triggers. I think I remember reading somewhere that Triggers have a lower total execution time limit per execution, but I can't remember where I saw it, and I can't find a source, even in Google's documentation.

This SO question is also similar...

I wouldn't say it's a bug, however as my own painfully experience, I can tell it's not the same running the script manually than through a time-driven trigger. Sometimes it's just slower, but others it fails for timeout.

I don't know your specifics (there is no code available), but I would recommend you to use a retry exponential backoff function wrapping any critical call and also check for a timeout warning (let's say at 5 minutes) within the main loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM