Service using too much computer time for one day - google-apps-script

This indicates that the script exceeded the total allowable execution time for one day. It most commonly occurs for scripts that run on a trigger, which have a lower daily limit than scripts executed manually. The limit as far as I am aware is 6 hours per day. None of my scripts run for that long.
Everything was fine earlier. Suddenly, over the last 3-4 days, all the scripts have started failing. I have no clue what's happening. My only hunch is that one of my scripts is going into an infinite loop. But still, if that happens, it will fail soon and collectively, all scripts would not run for 6 hours.
Please help to resolve this issue. I have a G suite id but Google mentioned that I get help at stackoverflow and that they cannot help.

The exception message should also tell you a lot about what is happening. If you are not sure which script is causing the issues you can try to go to the Google Apps Script Manager. In the menu bar on the left you will see a section called My Executions. If you click that you can see a list of scripts that ran and how long they ran for. This page also allows you to sort by duration and filter the results to hopefully help you figure out what is going on.
It possible that you have reached your quota. Having a Google Suite account allows you up to 6 hrs/day of Trigger Total Runtime. Also make sure you are not going over the limit on single script runtime as outlined here further down on the Quota For Google Services page.
For Google Suite Accounts the quota is:
Script runtime: 6 min/execution
Custom function runtime: 30 sec/execution

I had a similar problem. It's a little maddening because getting an error for the script leads one to believe it is a possible syntax problem. More likely, the script never ran in the first place, which is why you likely don't have a failed execution status for the trigger. What may have happened instead is that you have a script or scripts that are still firing for documents that no longer exist.
Navigate to "My Triggers" in the G Suite Developer Hub: https://script.google.com/home/triggers
Click on any time-based events and select "executions."
Search the "status" column for the words "Timed out," and check the duration.
Delete the trigger(s) that is timing out, or otherwise resolve why it is timing out (such as restoring the deleted document).
In my case, I had deleted several old spreadsheets, but one of my add-ons (Supermetrics) was still firing triggers. I had incorrectly assumed that when I deleted my spreadsheets the triggers would have gone with them. Instead they were firing and timing out after about six minutes, and then four hours later they would try to execute again. I added up the duration for all of these triggers and, sure enough, it exceeded my quota.
Delete those old triggers, and you'll likely be back within your quota limits the next day when it resets. This is what worked for me, but I imagine it's not a one-size fits all solution.

Related

How to control background execution of Apps Script Custom Functions?

The list of the Apps Script add-on executions shows that the custom functions are executed in the background every 20 minutes. How to control/avoid executions of custom functions in the background? The background executions of custom functions is a waste of resources. I would like to control the execution of my custom functions.
Check out Triggers
I'm not sure what kind of triggers you have installed, but it sounds like a time-based trigger.
If you go into the menu pictured above, you will be able to manage any triggers you have installed. Including changing the time period of your 20 minute one.
Quotas
One execution every 20 minutes is not something to worry about in terms of quotas, as you have the ability to run many many more executions. Though of course, if running it every 20 minutes is useless to you, by all means, change the period or delete it!

Is there a way to have exact control over google apps script trigger timing?

For understandable reasons Google seems to only be allowing script triggers with 15 minute tolerance on timing (when specifying an absolute time - they allow relative times precise to the millisecond). I'm wondering if I've missed something though. Is there a way of saying I want something to run at exactly 00:01 in a particular time zone every day?
As far as the documentation goes, you are right on the 15 minutes approximation. If you want a script to run exactly at a given time, you should run it using the Apps Script API from a web server of yours or even your desktop. To set it up, you can use this example as a reference.

Google Sheets On Form Submit Event - Complete Code Before Next Submission

I am using an On Form Submission trigger in a Google Sheet that I created. The problem that I am having is that there is a chance that the form could be submitted quicker than it takes to execute the code, so the first submission is interrupted.
Ideally, I would like it to complete the execution for the first submission, and as soon as it completes, begin on the second submission. Is this possible?
Two options.
LockService or deal with concurrency.
Others have begun investigating using Firebase as an alternative to the in-built LockService due to recent reliability issues.
Personally the latter option is my recommendation. i.e. Have your project cope with multiple entry points at uncontrollable times.
Good luck, I have been fighting for a good solution for over a year now (with my Choice Eliminator add-on). The problem is that Google process your script after the form is submitted, so there is no real way to prevent overlapping submissions.
Here is what I have found.
You can temporarly shut off the form from accepting answers: This was actually the best way I have found, but it tended to confuse the end-user, and they also potentially lost the info they filled out if they hit submit and it was closed. I also found that if there was any hiccup in the onFormSubmit function the form would stay closed until the owner re-opened it.
LockService. I tested this and it really didn't do anything to help with the overlapping submissions. It prevented my code from running twice, but then my code didn't run on the second submission.
I personally chose to remove everything and make the script run as fast as possible. With one exception, I grabbed the time the script started, and ended, then displayed the difference to the owner of the script so they at least knew how long there needed to be between submissions to not have an error.

Google App Script trigger is not firing

I am a Google App Script user since last 2 years. I see here in India during peak time i.e during evening the 1 minute trigger is not firing at proper time. Is there any server side issue or there is some other issue. Saying about the worse case scenarios, today my script trigger has not been fired since past 2 hours. I have correctly done logging. No log is printed means it does not even go to that method. Can anybody tell me what might be the exact reason behind it.
It might be beneficial to show us the code behind your script, given that there is a method that is potentially being skipped over. Have there been no errors thrown to you via the Google Apps Script notifications?
It seems, perhaps, your issue may fall into place with this currently reported error: https://code.google.com/p/google-apps-script-issues/issues/detail?id=2708
We're likely not going to be able to give you a precise answer to your problem if we can't examine what you're currently working with. I wish you luck in your endeavor, though.

catching Exceeded maximum execution time?

Is there anyway of catching this GAS error: "Exceeded maximum execution time"
I mean catching with try ... catch(e) // so far it's not working for me.
Thanks
As written in the comments to your question, thats not possible. But, however, you can set a flag in scriptDB or properties when execution starts and clear that flag when execution comes to a normal end, so you can find out during the next run wether your script came to a regular end when it was run last time and try to take corrective actions if not.
The answer above is correct; it's not possible. An easy alternative to the workaround that pbhd mentioned would be to simply track the runtime of your script (e.g. comparing results of new Date().getTime() at regular intervals) and run whatever you'd include under your catch statement right before you hit the maximum execution time. The maximum is 6 minutes (reference).
That way, you don't have to catch the error -- you can preempt it.
During normal testing, it is possible to accidentally create an infinite (or very long running) loop that consumes the daily execution time limit 100%.
Even if you realize what you have dome wrong immediately, you cannot immediately re-try with Google scripts for another 24 hours - thus slowing down ongoing development significantly and maybe forcing the developer to do some other work , taking his focus/"attention stream" away from the current problem. This is almost always bad.
My product ("IBM OLIVER CICS test/debug" - see Wikipedia article) solved this problem - and many others - around 37 years ago - by having a time limit on any particular transaction and intercepting the resulting time out, allowing options of:-
continuation or
examine/modify variables
"manual" re-try (for the same time) or
abort.
Google could implement this approach just as easily - by "pausing" if execution time is looking too heavy. I had a similar solution to other resources in OLIVER - such as excessive API calls ("possible macro loop") and excessive memory usage.
It seems it takes an "old timer" like me to provide solutions to problems that have existed "since the beginning of time" (and certainly before PC's were thought of).
Googles current "solution" (i.e. absolute limits) only helps Google keep its own servers from being swamped. It would be easy for them to do what OLIVER did all those years ago. By the way there should be no "IBM" prefix on the Wikipedia article - it was my own product and some clown Wikipedia editor altered it to include the prefix.
(By the way, Google do not prevent other scripts on same s/s running - that maybe only use minimal amounts of extra time ( i.e. Scripts on the same spreadsheet still work) . I tried renaming the original script as an experiment but it was stopped after a very short time with "exceeded execution time" error.
GIZ-A-JOB Google - you know its worth it!