So, let's think of it like this: I have 20 units of data where the processing of each unit takes 1 minute to be processed (total 20 minutes of processing), and the maximum execution time for an apps script function is (360 seconds), the thing is I dont want to divide them to like 4 parallel executions manually so I thought of this:
make a driver function to get the 20 units at once 2) check for current triggers.
if < 20 triggers are there, divide the units by the available triggers to create some sort of concurrency (then the whole execution will finish in 1 minute if n of triggers atm is 0.
if >=20 (max limit) sleep for a minute then check for available triggers again
run a function to delete each trigger after it finishes execution.
so is this achievable or is there a better way to workaround the max execution time and the concurrency problems in apps script?
I believe your goal is as follows.
Unfortunately, in the current stage, there are no methods for directly running the Google Apps Script with the asynchronous process. So, in order to achieve your goal, it is required to think of a workaround. In this answer, I would like to propose a workaround. The flow of this workaround is as follows.
By this, the script can be run with the asynchronous process.
Please install the library to your current Google Apps Script project. You can see the method for installing it at here.
// This is your current script.
function myFunction(e) {
// do something.
//return result; // Please return the values you want to return.
return e; // This is a sample return value for testing this script.
}
function doPost(e) {
return RunAll.RunFunctionsByDoPost(this, e);
}
// Please run this function.
function main() {
var url = "https://script.google.com/macros/s/###/dev"; // Here, please set the URL of Web Apps.
var token = ScriptApp.getOAuthToken();
var resource = [
{
functionName: "myFunction",
arguments: "sample parameter 1", // Please set the value you want to give.
webAppsURL: url,
accessToken: token,
},
{
functionName: "myFunction",
arguments: "sample parameter 2", // Please set the value you want to give.
webAppsURL: url,
accessToken: token,
},
{
functionName: "myFunction",
arguments: "sample parameter 3", // Please set the value you want to give.
webAppsURL: url,
accessToken: token,
},
];
var res = RunAll.DoWebApps(resource);
res.forEach(function (r) {
Logger.log(r.getContentText());
});
}
resouece
using a loop.https://script.google.com/macros/s/###/dev
.When above script is run, when your setting is correct, the following result is obtained.
{"FunctionName":"myFunction","Arguments":"sample parameter 1","Result":"sample parameter 1"}
{"FunctionName":"myFunction","Arguments":"sample parameter 2","Result":"sample parameter 2"}
{"FunctionName":"myFunction","Arguments":"sample parameter 3","Result":"sample parameter 3"}