1
votes

In google apps script, I want to write a trigger that fires everyday starting at say 8:57AM till 6:57PM. And it fires every hour. Via the Resources->Current Project triggers, I can set it up to fire hourly and write logic in the firing function to ignore if current time is not in range. But that way I can not force it to fire at 57th minute every hour.

I have seen programmatic triggers here

But that link does not clarify on how do we combine conditions(e.g. trigger hourly starting at nearest 8:57AM). I think we can cascade conditions like:

ScriptApp.newTrigger('authorizeToTrello').timeBased().everyHours(1).atDate(somedate);

I am not sure if such cascading leads to "AND" or an "OR" condition.

1
I would set it to trigger every minute and check the time, since you can't garantee that it'll run in the 57 minutes, I would give it a range, by making a script property variable that turns true in the 30-50minutes range of every hours, but doesn't execute anything else, and at anytime that has passed 57 minutes and the variable is true, set to to false teh scriptProperty and run the authentication.Kriggs
@Kriggs I have this option of running every minute. But I fear reaching execution limit quota per day which is 1-1.5 hrsrahulserver

1 Answers

0
votes

you cant cascade or use conditionals as part of the trigger creation.

instead your only option is to have a recurring 1minute trigger and check first thing if the current time meets your wanted time range.

i would suggest to not attempt being so precise and instead use a trigger of every 5 or 10 minutes. otherwise you need to have more complex logic (even with every 5 minutes) to handle overlapping triggers since each execution could last up to 6 minutes.