Mic*_*ael 5 gmail google-apps-script
这可能很奇怪,但我有一些代码可以通过我的电子邮件并使用标签来触发某些任务。例如,如果有人通过 Indeed 申请,Indeed 会向我发送一封电子邮件。过滤器将看到此电子邮件并应用“Applications/indeedApplication”标签。然后,每分钟运行一次的脚本会找到这个标签,并根据该标签自动执行一些操作。
大约 99.97% 的情况下这都可以正常工作。该脚本运行没有问题,并执行任务,应用已完成的标签,一切都按预期进行。0.03% 的时间,任务会失败,总是在同一点,并且总是出现相同的异常:
例外:不允许 Gmail 操作。
当脚本尝试在 GmmailThread(GmailApp API 的类)上运行 getLables() 函数时,它会失败。
有问题的代码:
function addICandidate() {
var label = GmailApp.getUserLabelByName("Applications/indeedApplication"); //Defines the label that identifies indeed applicatoins
var requests = label.getThreads(); //Returns an array of threads which have this label
if(requests.length > 3){requests.length = 3}; //This makes it so the script doesn't waste time looking through every application ever.
for ( var i in requests ) { //Starting a normal for loop
iLabels = requests[i].getLabels(); //Gets the labels of the Randomly fails here and only here
var checker = false; //used later to check if tasks were already completed
for (var k = 0 in iLabels) { //Starting another normal for loop
var individualLabel = iLabels[k].getName(); //Gets a list of the labels
if (individualLabel === completedLabelName) { //Checks if the label for completes tasks is present
var checker = true; //If they are, set checker to true (also used later)
}
}
if(checker){ //If the checker above is set to true
Logger.log("true"); //Do nothing (logger is just used in debugging)
}
else{ //Else (if the label is not completed and therefore, the tasks have not been done yet)
var thread = requests[i].Dostuff(); //Confidential stuff lives here
}
requests[i].addLabel(completedlabel); //After everything, apply the completed label so tasks are not done again on the next pass
}
}
}
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么它会在这里失败并且只有三千分之一的尝试。我显然无法用暴力来调试这个问题,所以任何关于为什么会发生这种情况的想法都会非常有帮助。
| 归档时间: |
|
| 查看次数: |
355 次 |
| 最近记录: |