我有一个脚本,需要每天凌晨执行。
我设置了自动时间触发器,该触发器每10分钟执行一次检查脚本,以查看是否在下一个小时之前10分钟。该脚本会将文本和电子邮件发送到我们的列表,并且可以正常运行(尽管执行过程需要5至20分钟)。
问题是人们收到重复的文本和电子邮件。
我怀疑原因是检查器脚本设置了脚本属性,但是直到脚本完成(与编写单元格类似),它才真正被设置。如果脚本执行时间超过10分钟,则脚本将在没有新属性的情况下再次开始执行,并使其运行两次。 我的问题是:“ setProperty()是立即发生还是在脚本末尾发生?”
如果它立即发生,那么我需要找出另一个原因,使脚本似乎两次执行两次。这是我的检查脚本供参考。请注意,当我手动执行sendComs(time)函数时,没有时间触发,它只会执行一次。因此看来问题出在下面。
function sendDaily () {
var today = new Date();
var hours = today.getHours();
var mins = today.getMinutes();
var scriptProperties = PropertiesService.getScriptProperties();
var timeLastTriggered = scriptProperties.getProperty('LastTime');
switch (timeLastTriggered) {
case '0':
if (hours >= 4 && mins >= 50 || hours >= 5) {
scriptProperties.setProperties({'LastTime':'5'})
sendComs('5:00 AM');
}
break;
case '5':
if (hours >= 5 && mins >= 50 || hours >= 6) {
scriptProperties.setProperties({'LastTime':'6'});
sendComs('6:00 AM');
}
break;
case '6':
if (hours >= 6 && mins >= 50 || hours >= 7) {
scriptProperties.setProperties({'LastTime':'7'});
sendComs('7:00 AM');
}
break;
case '7':
if (hours >= 7 && mins >= 30 || hours >= 8) {
scriptProperties.setProperties({'LastTime':'7.5'});
sendComs('7:30 AM');
}
break;
case '7.5':
if (hours >= 7 && mins >= 30 || hours >= 8) {
scriptProperties.setProperties({'LastTime':'7.6'});
sendComs('7:40 AM');
}
break;
case '7.6':
if (hours >= 7 && mins >= 30 || hours >= 8) {
scriptProperties.setProperties({'LastTime':'7.7'});
sendComs('7:50 AM');
}
break;
case '7.7':
if (hours >= 7 && mins >= 30 || hours >= 8) {
scriptProperties.setProperties({'LastTime':'7.8'});
sendComs('7:55 AM');
}
break;
case '7.8':
if (hours >= 7 && mins >= 30 || hours >= 8) {
scriptProperties.setProperties({'LastTime':'8'});
sendComs('8:00 AM');
}
break;
case '8':
if (hours >= 8 && mins >= 50 || hours >= 9) {
scriptProperties.setProperties({'LastTime':'9'});
sendComs('9:00 AM');
}
break;
case '9':
if (hours >= 11 && mins >= 50 || hours >= 12) {
scriptProperties.setProperties({'LastTime':'12'});
sendComs('12:00 PM');
}
break;
case '12':
if (hours >= 14 && mins >= 50 || hours >= 15) {
scriptProperties.setProperties({'LastTime':'15'});
sendComs('3:00 PM');
}
break;
case '15':
if (hours >= 17 && mins >= 50 || hours >= 18) {
scriptProperties.setProperties({'LastTime':'18'});
sendComs('6:00 PM');
}
break;
case '18':
if (hours >= 20 && mins >= 50 || hours >= 21) {
scriptProperties.setProperties({'LastTime':'21'});
sendComs('9:00 PM');
}
break;
case '21':
if (hours >= 23 && mins >= 50 || hours < 5) {
scriptProperties.setProperties({'LastTime':'0'});
sendComs('12:00 AM');
}
break;
}
}