Google App Script trigger is not firing - google-apps-script

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.

Related

Strange Google Appscript Error "Must only be whole numbers."

Amateur here.
An image above shows the Logger.log() being performed at the very end of the code. Yet somehow it gives off an Error that I cannot search up in Google (First time Googling can't help me, yikes)
Has anyone gotten a clue? A week ago, it worked perfectly fine before I temporarily abandon the project to focus on other real-life matters. Came back and re-ran the thing without any edit, and this error shows up.
Unfortunately I am very uncomfortable sharing the code - this Appscript utilizes a Google Spreadsheet that automates all the data and numbers for a "roleplaying game" that involves numbers related to money and purchasing. It's closest counterpart would be DnD, but it's much different, more embarrassing, and arguably more confusing when trying to explain it. If however I need to share the whole code for debugging purposes (200 lines), then I will.

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.

Why are my PushSubscriptions expiring so quickly?

I followed this tutorial to implement push notifications in my web app, and while they work, they stop working very quickly. It seems to handle the first couple of notifications well, but after that, sometimes when less than five minutes has gone by, the subscription expires, according to my back-end. I get an error code of 410 from the push service which the tutorial says is meant to indicate that the subscription expired.
This is crazy, how can a subscription expire in less than five minutes? I searched up my issue and it seems no one else has had this problem, some even saying that subscriptions can last years!
I tried implementing an event listener in my service worker for the "pushsubscriptionchange" event, but according to Serginho's answer, Chrome did not implement that event as of 2019, and I don't think that's changed since then.
Oh, and while Chrome can handle the subscription (but only once/twice as explained above), Firefox doesn't even do anything. I feel like I'm going crazy. If I test the push subscription feature itself using this site, however, it works in Firefox! and Chrome! What are they doing that I'm not? They show the exact same code as the tutorial I linked above.
What even can I do at this point? I've considered perhaps creating an interval with setInterval() and just resubscribing the user every second or so, but I don't think that'll work.
Any help would be appreciated.
You absolutely need to handle the pushsubscriptionchange in your service worker. Otherwise when a subscription expires and is replaced with a new one you will lose it.
Chrome and most browsers actually trigger that event (I don't know where you read something different). I am sure that it is triggered because on our push service we receive thousands of hits per hour from that event.
Take a look at our service worker if you need inspiration on how to implement that event. Then on your server you simply replace the old subscription with the new one.

Service using too much computer time for one day

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.

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.