为什么基于时间的 GAS 触发器在 V8 中因未知原因被禁用? [英] Why does time-based GAS Trigger get disabled for unknown reason in V8?

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

问题描述

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

I have (amongst others) the following four functions.

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

我有一个触发器:

  1. 在表单提交时运行.
  2. 调用 fallback() 将某些内容发布到电子表格以供审核.
  3. fallback 调用 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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆