Why does time-based GAS Trigger get disabled for unknown reason in V8?

纵然是瞬间 提交于 2021-02-07 20:22:11

问题


I have (amongst others) the following four functions.

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

I have a trigger that:

  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.

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.

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]);
    }
  }
}

Use-case example:

  1. A customer submits a request for a pricing offer for new door.
  2. Then they also submit a request for a pricing offer an extension to their house.
  3. This door will most likely be part of the extension so ideally we would send this request to a company that deals with house extensions as well as doors.
  4. But if the door request was processed immediately it might have been sent to a specialist that exclusively deals with doors.

回答1:


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



来源:https://stackoverflow.com/questions/60455263/why-does-time-based-gas-trigger-get-disabled-for-unknown-reason-in-v8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!