I have a few scripts that I want to run overnight so I've set up script triggers to execute these. Its all pretty straightforward stuff and they run fine. But occasionally, say once a month, one of them fails to execute. No error messages are sent to me by Google or anything like that.
Has anyone else experienced this? Has anyone got any ideas I can check for this error? Obviously if its the actual trigger that's not firing in the first place then the code won't actually run and therefore it won't be able to run any checks.
I'll also flag this with Google themselves in google-apps-script-issues forum.
I have a trigger set to fire every five minutes and a few times a month it will fail. Often it will say something about the function not being found.
You can be notified of an execution failure by setting up an "execution failure notice". In Resources > Current Script's Triggers, after each trigger will be a "notifications" link. Clicking it will open the "Execution failure notifications" window.
You have some choices about timing of the email notification of the failure.
Maybe: I suspect that, after I edit my code, sometimes the triggers miss fire. But I have never double checked this.
Suggestions:
1) add some logging and at the end of the script, grab the log and email it back to yourself.
2) Add a try catch around your code and email any errors that you catch back to yourself.
Google scripts are throttled in various ways and your script may be hitting up against one of these limits. There are limits on the number of emails you can send and limits on execution time of the script in addition to others.
Related
I have a Google Script running every 5 minutes. It works except randomly there are sudden crashes and the script/trigger won't survive that. So, for many different reasons, the script stops running after some weeks of continuing runtime. At this point, I would need a notification.
How can I get a notification if a function (script) hasn't run in say 2 hours? Doesn't matter what the technique/notification is, but probably email would be great for the notification. I don't think the solution can be in the script code itself, because the script randomly (every few weeks) crashes at Google's side and there's nothing I can do about that.
Google Apps Script installable triggers automatically set an email notification. You could edit when it should be sent (i.e. send immediately) and you could add more notifications. NOTE: This can only be done manually.
The above will work for "normal" failures but it there is a service outage or other platforms failures the notification might not be sent.
One option is to log the executions somewhere then set a second trigger to check that the first trigger ran every time that it should do it as expected. NOTE: The failure that prevented that the first trigger run might also prevent that his second trigger run i.e. a service outage so you might want to set other monitoring measures accordingly the the severity/priority of this failure and your project budget.
I have this email from google.
Your script, Drive Migrator, has recently failed to finish successfully. A summary of the failure(s) is shown below. To configure the triggers for this script, or change your setting for receiving future failure notifications, click here.
There are about 200 messages of the format:
Start 1/1/19 4:53 PM
Function processFilesAndFolders
Error Message Authorization is required to perform that action.
Trigger time-based
End 1/1/19 4:53 PM
When i click there i fund there is an empty trigger and no further information.
Project -
Last run -
Deployment -
Event Time-based
Function -
Error rate -
Its very strange given nobody was on the system at this time, and I cannot see any details about the trigger.
How do I see what is happening here? Is someone on my system, trying to move my files around? How is is possible to have a trigger that is void of information like this? It looks somewhat hacky. Can I centrally disable this "drive migrator"?
I found an old question about this: Drive Migrator Fail Message
But, perhaps it does not have enough information to get a proper answer.
I also contacted google support directly, but they said that asking here is the only way to get technical support on this service. I understand this is not the best "stackoverflow type question", but I'm at a loss on where to get further information about this.
The failure notifications likely occur when a Google Script is deleted from your Drive without de-authorization or when the permissions get revoked for some reason.
Go here and you'll find a list of all triggers running under your Google account. Delete the one associated with your Failure emails.
This guide explains how you can unsubscribe from the failure emails and also properly de-authorize the associated script.
I am using a script which is found here: https://moz.com/ugc/updated-tool-seomoz-api-data-for-google-docs
I would like to trigger this to run once an hour (as a test, later once a month); to facilitate this I set up a time driven trigger in the script editor UI.
I need to test that the trigger is actually working. The issue is that I do not expect any of the data to change when the script runs (might change once a month max)...
So I looked to the script editor and found View > Execution Transcript. Perfect!
Except that I get this message:
No execution transcripts found. Please run your script and try again.
This doesn't seem to be consistent with the expected behaviour after reading the Google Apps Script documentation page, which says:
Every time you run a script, Google Apps Script records an execution
transcript, which is a record of each call to a Google Apps Script
service that is made while the script runs.
(Nothing in the logs either by the ways, though maybe this is something that needs to be turned on by the script itself; not sure).
So how can I test to see that my time driven trigger works, and that the script is being run each hour?
Final note: The script is executed by calling a function in the spreadsheet, as explained in the link at the top of the question.
If you have not yet run it manually, there may be an issue with it being given the proper permissions. Your first step would be to run the code manually using the play button. Once you know that the code itself will run successfully and has the right permissions, you can move to triggering it automatically.
Your next step is to shorten your trigger time so that it executes more frequently giving you more instances to check the function. Depending on the structure of your code, you can add Logger.log() calls at different steps to make sure that all portions are being called that need to be. You can then check you logs instead of the execution transcript as well.
These Logger.log() calls could include the time at which is was called to be able to verify that it was at the time/ frequency you need.
Ok, I don't know how great this answer is... but:
For me (as per my comment to MasterCrander), running the script by means of using the function inside the spreadsheet didn't actually affect the execution transcript, but when it ran via the time driven trigger it made it into the transcript.
Problem solved.
I am writing an immediate response code in google script which must monitor inbox at current time and if it detects a new e-mail with given subject then it runs the code and replies to the e-mail and at the end it marks the e-mail as read.
The whole stuff works fine, however I want it to get started more frequently than once in a minute. Thus I guess I can't use trigger option from the scripts interface. Will it work if I won't specify a trigger? How can I organize all this? I am using this stuff with google free quota for my personal use only.
thanks beforehand
Its not advisable to do what you want because you will run out of quota.
But its possible. Not with triggers as they run at most once a minute.
If you must, write a htmlservice app with a setInterval. Call a server method to do your work. Leave the webapp open all day.
I was wondering if there was a way to run a script requiring authorization without having to call it twice. For example, if I have a link on my google site that calls a script, I have to click on it two times - once to begin the authorization process, and once to actually run the script afterwards. I feel like this would be very confusing to users.
Thanks!
Jeff
There is no way to avoid this but I've found that it was generally less confusing to create a dummy function (that I usually call 'Authorize') that has to be called once and that does nothing else than trigger the authorization process and show a small explanation text. This makes things probably more clear for a 'normal' user as it is a separate process and not a repetition that gives the feeling something is wrong...