TimerTriggerによって動作するAzure Functionsの、TimerTriggerイベントの発生タイミングは、以下のサイトのNCRONTAB 式で指定できる。
https://docs.microsoft.com/ja-jp/azure/azure-functions/functions-bindings-timer?tabs=java#ncrontab-expressions
例えば、21時45分0秒にTimerTriggerイベントが発生するようにするには、NCRONTAB式で「0 45 21 * * *」と指定すればよいが、NCRONTAB式の既定のタイムゾーンは協定世界時 (UTC) になっているため、これを日本時間に変更する必要がある。
今回は、NCRONTAB式のタイムゾーンを日本時間に変更した上で、TimerTriggerによって動作するAzure Functionsの関数を日本時間の指定した時刻に実行してみたので、その手順を共有する。
前提条件
下記記事のサンプルプログラムをAzure Functionsにデプロイ済であること。
NCRONTAB式のタイムゾーンを日本時間に変更
NCRONTAB式のタイムゾーンを日本時間に変更するのは、Azure Portal上で実行できる。その手順は、以下の通り。
1) Azure Functionsの概要を表示した状態で、「構成」メニューを押下する。

2) NCRONTAB式のタイムゾーンを日本時間に変更する設定を追加するため、「新しいアプリケーション設定」ボタンを押下する。

3) 名前に「WEBSITE_TIME_ZONE」、値に「Asia/Tokyo」を指定し、「OK」ボタンを押下する。

4) 以下のように、名前が「WEBSITE_TIME_ZONE」であるアプリケーション設定が追加されていることが確認できるので、「非表示の値です。値を表示するには、クリックしてください」のリンクを押下する。

5) 名前が「WEBSITE_TIME_ZONE」の値が、指定した「Asia/Tokyo」と設定されていることが確認できる。ここで「保存」ボタンを押下する。

6) 以下の確認画面が表示されるので、「続行」ボタンを押下する。

TimerTriggerによって動作するAzure Functionsの関数の、設定変更前・設定変更後のログの内容は以下の通りで、設定変更後は赤枠のログ出力された時刻が日本時間になっていることが確認できる。
サンプルプログラムの変更と実行結果(ローカル)
前提条件の記事のプログラムの「TimerTriggerTestHandler.java」を、以下のように、21時45分0秒にTimerTriggerイベントが発生するように変更後、ローカル環境で実行した結果は、以下の通り。
package com.example;
import org.springframework.cloud.function.adapter.azure.FunctionInvoker;
import com.example.model.TimerTriggerParam;
import com.example.model.TimerTriggerResult;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.TimerTrigger;
public class TimerTriggerTestHandler
extends FunctionInvoker<TimerTriggerParam, TimerTriggerResult>{
/**
* TimerTriggerによって、DemoAzureFunctionクラスのtimerTriggerTestメソッドを呼び出す.
* @param timerInfo TimerTriggerイベント情報
* @param context コンテキストオブジェクト
*/
// 「schedule = "0 45 21 * * *"」で、21時45分0秒にTimerTriggerイベントが発生するようになっている
@FunctionName("timerTriggerTest")
public void timerTriggerTest(@TimerTrigger(name = "timerTriggerTest"
, schedule = "0 45 21 * * *") String timerInfo,
ExecutionContext context) {
context.getLogger().info("TimerTriggerTestHandler timerTriggerTest triggered: "
+ timerInfo);
TimerTriggerParam param = new TimerTriggerParam();
param.setTimerInfo(timerInfo);
param.setLogger(context.getLogger());
handleRequest(param, context);
}
}その他のソースコード内容は、以下のサイトを参照のこと。
https://github.com/purin-it/azure/tree/master/azure-functions-timer-trigger-manual/demoAzureFunc
「mvn azure-functions:run」で実行した結果は以下の通りで、赤枠のログの「Next」を確認すると、21時45分0秒にTimerTriggerイベントが発生していることが確認できる。

なお、ローカル環境でのデプロイ・実行方法については、以下の記事の「サンプルプログラムの実行結果(ローカル)」を参照のこと。
サンプルプログラムの変更と実行結果(Azure上)
前提条件の記事のプログラムの「TimerTriggerTestHandler.java」を、以下のように、21時55分0秒にTimerTriggerイベントが発生するように変更後、Azure環境上で実行した結果は、以下の通り。
package com.example;
import org.springframework.cloud.function.adapter.azure.FunctionInvoker;
import com.example.model.TimerTriggerParam;
import com.example.model.TimerTriggerResult;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.TimerTrigger;
public class TimerTriggerTestHandler extends FunctionInvoker<TimerTriggerParam, TimerTriggerResult>{
/**
* TimerTriggerによって、DemoAzureFunctionクラスのtimerTriggerTestメソッドを呼び出す.
* @param timerInfo TimerTriggerイベント情報
* @param context コンテキストオブジェクト
*/
// 「schedule = "0 55 21 * * *"」で、21時55分0秒にTimerTriggerイベントが発生するようになっている
@FunctionName("timerTriggerTest")
public void timerTriggerTest(@TimerTrigger(name = "timerTriggerTest", schedule = "0 55 21 * * *") String timerInfo,
ExecutionContext context) {
context.getLogger().info("TimerTriggerTestHandler timerTriggerTest triggered: " + timerInfo);
TimerTriggerParam param = new TimerTriggerParam();
param.setTimerInfo(timerInfo);
param.setLogger(context.getLogger());
handleRequest(param, context);
}
}その他のソースコード内容は、以下のサイトを参照のこと。
https://github.com/purin-it/azure/tree/master/azure-functions-timer-trigger-manual/demoAzureFunc
TimerTriggerによって動作するAzure Functionsの関数の、実行後のログの内容は以下の通りで、赤枠のログの「Next」を確認すると、21時55分0秒にTimerTriggerイベントが発生していることが確認できる。

なお、Azure環境でのデプロイ・実行方法については、以下の記事の「サンプルプログラムの実行結果(Azure上)」を参照のこと。
要点まとめ
- TimerTriggerによって動作するAzure Functionsの関数を日本時間の指定した時刻に実行するには、Azure Portal上でNCRONTAB式のタイムゾーンを日本時間に変更した上で、NCRONTAB式で発生タイミングを指定すればよい。








