I inherited project and I'm trying to sanitise the functions. I have 50 functions I'm wondering what's the best way to see when the functions were last run? From the firebase project console (functions tab) I can get logs for the different functions. Some functions have no logs. Can I assume if a function has no logs that it never ran?
Related
I have 13 Google Cloud Functions running in my Google Cloud Project. Several of them are triggered by Google Cloud Scheduler. I went to make an edit to one of the functions the other day and got the following error when trying to view the "SOURCE".
When looking into this issue, the culprit seems to be that the Archive Bucket has been deleted or that the name has changed. When looking through the Container Registry as well as the buckets, I can confirm that they are no longer there. I think another developer in the project may have accidentally deleted them when cleaning up images from an old project.
That being said, when looking at the logs I have noticed that the functions being triggered by Google Cloud Scheduler are still successfully running on their schedules even though I can no longer access the source code. The functions are logging data the I console within the source code even though it is no longer there.
My question is whether or not these are recoverable and what it would take to find them.
I have tried looking for the images and the buckets to see if they were renamed and I could not find them. I also created a new function in the same region and it spun up a new image and bucket, but it did not contain any reference to the other missing functions.
It is not possible to access the source code of a Google Cloud Function if the bucket that contained the code has been deleted. The source code is stored in the bucket, so if the bucket is deleted, the code is also deleted. If the function is still running, it is because the code has been deployed and is being run from a different location. You can view the logs for the function to see what code is being executed, but you will not be able to retrieve the original source code.
If you need to access the source code for the function, you will need to redeploy the code to a new bucket. You can do this by creating a new bucket and uploading the code, or by using the Cloud Functions API or the gcloud command-line tool to deploy the code to the new bucket.
I'm creating a Gmail Addon and for some reason AppScript has stopped updating when I save my code. Up until last week I would make changes, save my code, refresh Gmail add the updates would be there. The addon is installed as a developer addon using the HEAD version.
First question, do I have to re-deploy or anything after making changes? As far as I can see in the documentation the approach above should work fine.
I'm using the Google Oauth2 library to login into an external service. It was all working fine last week and now I've just noticed these errors come up in the execution hints...
Method Properties.deleteProperty invoked in the global scope.
File: Storage
Line: 125
This function invocation will fail when the script is run as an Add-on in AuthMode.NONE.
Method Cache.remove invoked in the global scope.
File: Storage
Line: 127
This function invocation will fail when the script is run as an Add-on in AuthMode.NONE.
Method ScriptApp.getScriptId invoked in the global scope.
File: Service
Line: 36
This function invocation will fail when the script is run as an Add-on in AuthMode.NONE.
I don't have access to the files that the errors are referring too though so how am I supposed to fix them?
Also if there are errors in the execution hints will that prevent any updates to the code? Is that the reason I wouldn't be seeing my updates come through?
I know the updates aren't working because I'm seeing nothing in the logs where I was before.
Really appreciate any help. I've spent hours going through the docs, SO and the issue tracker trying to figure this out.
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.
According to Google app script time-trigger documentation https://developers.google.com/apps-script/guides/triggers/installable#limitations,
Time-driven triggers cannot run more frequently than once per hour. How can I use app script to write an add-on that process large amount of data?
If I run a trigger, it will only allow me to trigger once. I can't chain the triggers so it can continuously run.
You cannot do so using triggers because they would run at most once per hour in the context of an add on.
What you can do is to initiate such processing client-side while possibly showing progress on a sidebar. The client js in the sidebar can chain server calls.Of course being all client-side means the user must have opened the file and if they close the browser tab or navigate away, the chain calls will stop. That can be handled by alerting the user and making them aware that a "sync" happens and sometimes takes a while. Currently there is no other way to handle this unless your client call and time trigger call another server which does the processing, like appengine or gce.
I have a written a web Apps Script which is deployed to run in the context of user accessing the web app.
Is it possible to export web Apps Script's Execution Transcript programatically?
Not directly.
You won't get a full stack trace, but you can be meticulous with Logging everything you want to be notified with. At the end of the script you could extract the log and email that.
Logger.getLog();
If you really wanted to be fancy, there are a few implementations of custom Loggers which extent the standard Logger.log(). For instance if you had an object that every time you send a log message to it, it would time-stamp overall duration, time since last log and the message passed to it, all to Logger.log. Same object could have a getLog(0 method of its own which did extra stuff - should you wish.
There is a notable logger library at Google Apps Script Examples by Peter Herrmann which will also allow you to log to a spreadsheet.
But in short, no, you cannot export the execution log.