clasp: Nested trigger doesn't fire on V8 engine

Viewed 91

Problem

Nested trigger on GAS v8 engine doesn't work if I use clasp typescript project. "Nested trigger" means a scheduled function which is programmatically created by another scheduled function.

  • clasp: v2.3.0

How to reproduce

  1. Create clasp project
    clasp create --type standalone
  2. Create a TypeScript file called main.ts with the following contents:
// Set trigger on a specific time.
function setTrigger(time:Date, func:string): void {
  console.log('This is scheduling: ' + func + ' on ' + time);
  ScriptApp.newTrigger(func)
      .timeBased()
      .at(time)
      .create();
}
// Set trigger on 5 minutes after.
function schedule() {
  const toBeScheduled = new Date();
  toBeScheduled.setMinutes(toBeScheduled.getMinutes() + 5);
  setTrigger(toBeScheduled, "doSomething");
}

// function which will fire.
function doSomething() {
  console.log("DO SOMETHING");
}
  1. Create a json file called tsconfig.json with the following contents:
{
  "compilerOptions": {
    "lib": ["esnext"],
    "target": "ES2019",
    "experimentalDecorators": true
  }
}
  1. push code
    clasp push
  2. Set trigger for schedule() function every 5 minutes so that the doSomething() fire every 5 min.

but actually the doSomething() doesn't fire. The trigger is set but it will be disabled with UNKNOWN cause.

Note

  1. If I manually execute schedule(), then doSomething() fires as expected.
  2. If I create a GAS project with exactly same contents without clasp, then doSomething() fires as expected.
  3. If I push code without v8 engine as following, then everything works fine.
    • Remove "runtimeVersion": "V8" from appsscript.json
    • Remove tsconfig.json file from project.

Is there something I'm missing?

Update(2020/04/18)

I have created issue on the issue tracker.
https://issuetracker.google.com/154366756

0 Answers
Related