Google Apps script has the limitation of 6 hours triggered scripts per day per account.
I recently started getting the alerts Service using too much computer time for one day
.
Is there a way track the total time of triggered scripts by project?
I found so far this post , but then I'd need to lookup all of my 50 projects.
If my understanding is correct, how about this method? By the update of Apps Script API, the method for retrieving the process of project was added. I thought that this can be used for above situation.
startTime
and endTime
.Before you use this script, please enable Apps Script API as follows.
Enable Apps Script API at API console:Please add the following scopes to the Manifest file (appsscript.json
).
"oauthScopes": [
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/script.processes"
]
Before you run this script, please set startTime
and endTime
. This is the period for calculating the total time. In this sample script, the total time from 2019-02-07T00:00:00.000Z
to 2019-02-08T00:00:00.000Z
is calculated.
function myFunction() {
var startTime = "2019-02-07T00:00:00.000Z"; // Please set this.
var endTime = "2019-02-08T00:00:00.000Z"; // Please set this.
var params = {headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}};
var data = [];
var nextPageToken = "";
var url = "https://script.googleapis.com/v1/processes";
do {
var query = "?fields=%2a" +
"&pageToken=" + encodeURIComponent(nextPageToken) +
"&userProcessFilter.types=TIME_DRIVEN" +
"&userProcessFilter.startTime=" + encodeURIComponent(startTime) +
"&userProcessFilter.endTime=" + encodeURIComponent(endTime);
var res = JSON.parse(UrlFetchApp.fetch(url + query, params).getContentText());
Array.prototype.push.apply(data, res.processes);
nextPageToken = res.nextPageToken || "";
} while (nextPageToken);
var result = data.reduce(function(obj, e) {
obj[e.functionName] = obj[e.functionName] ? obj[e.functionName] + Number(e.duration.replace("s", "")) : Number(e.duration.replace("s", ""));
return obj;
}, {});
Logger.log(result)
}
As a sample situation, when 2 functions of myFunction1
and myFunction2
are run by the time-driven trigger, this script returns the following result. The result means that for startTime
and endTime
, the total execution times of myFunction1
and myFunction2
are 123.456 s and 12.345 s, respectively.
{
"myFunction1": 123.456,
"myFunction2": 12.345
}
startTime
and endTime
, a timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: 2014-10-02T15:01:23.045123456Z
. This is from the official document.If this was not useful for your situation, I apologize.