本文介绍了为什么在V8中出于未知原因禁用基于时间的GAS触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我(除其他外)具有以下四个功能.

I have (amongst others) the following four functions.

  • fallback()
  • newSubmission()
  • installSubmissionTrigger()
  • uninstallSubmissionTrigger()

我有一个触发器:

  1. 运行表单提交.
  2. 调用 fallback(),将某些内容发布到电子表格中进行审核.
  3. 后备调用 installSubmissionTrigger().
  4. installSubmissionTrigger 创建每分钟运行的基于时间的触发器.
  5. 触发器调用 newSubmission().
  6. newSubmission 做我想要的事情,并调用 uninstallSubmissionTrigger().
  7. uninstallSubmissionTrigger 删除基于时间的触发器.
  1. Runs on form submission.
  2. Calls fallback() that posts something to the Spreadsheet for review.
  3. fallback calls installSubmissionTrigger().
  4. installSubmissionTrigger creates a time-based trigger running every minute.
  5. The trigger calls newSubmission().
  6. newSubmission does something I want and calls uninstallSubmissionTrigger().
  7. uninstallSubmissionTrigger removes the time-based trigger.

在Rhino上所有这些都可以正常工作,但是当我启用V8时,基于时间的触发器由于应有的未知原因而被禁用.

All of this works fine using Rhino but when I enable V8 the time-based trigger becomes disabled for unknown reasons when it is supposed to run.

另外,在使用V8时,如果我手动运行 installSubmissionTrigger(),触发器也会触发.
如果我手动运行 fallback(),触发器也会触发.

Also when using V8, if I run installSubmissionTrigger() manually, the trigger does fire.
If I run fallback() manually, the trigger also does fire.

触发器被禁用的未知原因是什么?

What could be the unknown reason the trigger becomes disabled?

function fallback(event) {
  ...
  installSubmissionTrigger();
  ...
}

function newSubmission() {
  ...
  uninstallSubmissionTrigger();
  ...
}

function installSubmissionTrigger() {
  var properties = PropertiesService.getScriptProperties();
  if(!properties.getProperty("triggerID")) {
    var trigger = ScriptApp.newTrigger('newSubmission').timeBased().everyMinutes(1).create();
    properties.setProperty("triggerID", trigger.getUniqueId());
    Logger.log("Creating newSubmission trigger: " + trigger.getUniqueId());
  }
}

function uninstallSubmissionTrigger() {
  var properties = PropertiesService.getScriptProperties();
  properties.deleteProperty("triggerID");
  // Loop over all triggers.
  var allTriggers = ScriptApp.getProjectTriggers();
  for (var i = 0; i < allTriggers.length; i++) {
    // If the current trigger is the correct one, delete it.
    if (allTriggers[i].getHandlerFunction() === 'newSubmission') {
      ScriptApp.deleteTrigger(allTriggers[i]);
    }
  }
}

用例示例:

  1. 客户提交了新门的价格报价请求.
  2. 然后,他们还提交了定价请求,以扩展房屋.
  3. 这扇门很可能是扩展的一部分,因此理想情况下,我们会将请求发送给处理房屋扩展和门的公司.
  4. 但是,如果立即处理了门请求,则可能已将其发送给专门处理门的专家.

推荐答案

已经报告了您遇到的此问题,它与V8运行时有关[1].您可以使用运行预期版本的 DEPRECATED_ES5 运行时版本.

This issue you're having has been reported and it's related with V8 runtime [1]. You could work with DEPRECATED_ES5 runtime version which is working as expected.

[1] https://issuetracker.google.com/issues/150756612

这篇关于为什么在V8中出于未知原因禁用基于时间的GAS触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 06:58