Azure Functions TimerTrigger 计划在特定时间不起作用

问题描述 投票:0回答:1

我正在使用 TimerTrigger 使用 Azure Functions,并且遇到了一个问题:间隔计划运行良好(例如,每分钟、每 5 分钟),但特定计划未按预期触发。

@FunctionName("MyFunction")
    public void run(
        @TimerTrigger(name = "timerInfo", schedule = "0 * * * * *") // Executes every minute
        // Cron expression for every hour
            String timerInfo, 
            final ExecutionContext context) {

        context.getLogger().info("Java Timer trigger function executed at: " + Instant.now());
    // Function logic...
}

我尝试使用不同的 UTC 格式为 TimerTrigger 设置各种时间表,例如:

0 30 5 * * * (expected to trigger at 5:30 AM UTC daily)
0 15 12 * * * (expected to trigger at 12:15 PM UTC daily)

运行这些计划后,该函数成功执行,终端中没有任何错误。但是,我注意到没有任何日志表明计时器触发功能已启动,例如“计时器触发功能开始于:...”。

java cron azure-functions scheduling timer-trigger
1个回答
0
投票

我已经创建了一个 Java 计时器触发器 azure 函数,并且能够按预期在指定的时间表触发该函数。

代码片段:

 @FunctionName("TimerTriggerJava1")
    public void run(
        @TimerTrigger(name = "timerInfo", schedule = "<cronexpression>") String timerInfo,
        final ExecutionContext context
    ) {
        context.getLogger().info("Java Timer trigger function executed at: " + LocalDateTime.now());
    }

修改函数代码中的CRON表达式后运行

mvn clean install
,然后运行
mvn azure-functions:run

05:30 AM- CRON 表达式:

0 30 5 * * *
:

Functions:

        TimerTriggerJava1: timerTrigger

For detailed output, run func with --verbose flag.
[2024-11-02T23:58:53.695Z] Worker process started and initialized.
[2024-11-02T23:58:55.457Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2024-11-03T00:00:00.185Z] Executing 'Functions.TimerTriggerJava1' (Reason='Timer fired at 2024-11-03T05:30:00.0402341+05:30', Id=592b060a-ebab-45cb-a9b4-4608f67091f5)
[2024-11-03T00:00:00.554Z] Function "TimerTriggerJava1" (Id: 592b060a-ebab-45cb-a9b4-4608f67091f5) invoked by Java Worker
[2024-11-03T00:00:00.554Z] Java Timer trigger function executed at: 2024-11-03T05:30:00.524233
[2024-11-03T00:00:00.627Z] Executed 'Functions.TimerTriggerJava1' (Succeeded, Id=592b060a-ebab-45cb-a9b4-4608f67091f5, Duration=552ms)

enter image description here

12:15 PM - CRON 表达式:

0 15 12 * * *
:

Functions:

        TimerTriggerJava1: timerTrigger

For detailed output, run func with --verbose flag.
[2024-11-03T06:43:51.205Z] Worker process started and initialized.
[2024-11-03T06:43:53.745Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2024-11-03T06:45:00.109Z] Executing 'Functions.TimerTriggerJava1' (Reason='Timer fired at 2024-11-03T12:15:00.0339520+05:30', Id=abcfc9ab-838e-41f7-820a-5443710f24e1)
[2024-11-03T06:45:00.288Z] Function "TimerTriggerJava1" (Id: abcfc9ab-838e-41f7-820a-5443710f24e1) invoked by Java Worker
[2024-11-03T06:45:00.288Z] Java Timer trigger function executed at: 2024-11-03T12:15:00.264498500
[2024-11-03T06:45:00.326Z] Executed 'Functions.TimerTriggerJava1' (Succeeded, Id=abcfc9ab-838e-41f7-820a-5443710f24e1, Duration=272ms)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.