问题
I'm trying to trigger the execution of a function after like 1 second but google execute the function after 40 seconds or something 2 minutes.
Here is my code
function testFunc () {
Logger.log("test called");
}
function myFunction() {
const now = Date.now();
const dateNow = new Date(Date.now());
const dateLater = new Date(now + 1000);
const trigg = ScriptApp.newTrigger('testFunc')
.timeBased()
.inTimezone("Europe/Paris")
// .at(dateLater) // 1sec
.after(1000) // 1sec
.create();
}
I tried with the after
and the at
functions but both doesn't work.
When I look in the execution page I have this history showing the time between the execution of myFunction
and testFunc
.
Head testFunc Time-Driven Oct 15, 2019, 2:06:35 PM 0.009 s
Completed
Head myFunction Editor Oct 15, 2019, 2:05:33 PM 0.589 s
Completed
Head testFunc Time-Driven Oct 15, 2019, 2:04:15 PM 0.202 s
Completed
Head myFunction Editor Oct 15, 2019, 2:02:57 PM 0.46 s
Completed
The documentation on time driven triggers says that
The time may be slightly randomized — for example, if you create a recurring 9 a.m. trigger, Apps Script chooses a time between 9 a.m. and 10 a.m.
And I'm trying to have my trigger execute after just a few seconds (between 5 and 10) is there anyway to do that ?
回答1:
You are right about the cause of the randomized times, however, there is no way to force this to be untrue.
You have a couple of alternatives:
- Consider if you really need to wait before your other function is called. (if you are testing if the data manipulation on the main function worked, you don't need to wait.)
- Use Utilities.sleep() to add your delay. This might run over the 6 minutes execution time, be careful.
Hope this helps!
来源:https://stackoverflow.com/questions/58394838/google-apps-script-trigger-execution-too-late