Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

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

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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...