3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ScriptApp.newTriggerでatHourの前にevery***は必須?らしい

Posted at

日本時間朝5時に時間トリガーを設定しようとしてハマったのでメモ。

setTrigger.gs
function setTrigger(){
  ScriptApp.newTrigger("myFunction")
    .timeBased()
    .atHour(5)
    .create();
}

条件で朝5時に一回だけ起動する予定だったのがなぜか起動しない。。。

うむむ。

デバッグしてみたところ、どうやらnewTriggerのところで止まってしまうらしい。。
Timezoneの設定なのかと悩んでいろいろ試してみた結果、everyDays(1)を挟むことで使えるようになるみたい。。。

setTrigger.gs
function setTrigger(){
  ScriptApp.newTrigger("myFunction")
    .timeBased()
    .inTimezone("JST")
    .everyDays(1)
    .atHour(5)
    .create();
}

トリガーは1回きりなのでmyFunction内でScriptApp.deleteTrigger()メソッドで削除で対応。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?