javacronazure-functionsschedulingtimer-trigger

Azure Functions TimerTrigger Schedule Not Working for Specific Times


I'm working with Azure Functions using a TimerTrigger, and I'm experiencing an issue where interval schedules work perfectly (for example, every minute, every 5minutes), but specific schedules do not trigger as expected.

@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...
}

I attempted to set various schedules for the TimerTrigger using different UTC formats, such as:

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

After running these schedules, the function executed successfully without any errors in the terminal. However, I noticed that there were no logs indicating that the timer trigger function started, such as "Timer Trigger function started at: ...".


Solution

  • I have created a Java Timer trigger azure function and able to trigger the function at specified schedules as expected.

    Code Snippet:

     @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());
        }
    

    Run mvn clean install after modifying the CRON expression in function code and then run mvn azure-functions:run.

    05:30 AM- CRON expression: 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 Expression: 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