Azure Function App Timer trigger not firing in UTC. How to fix?

Devi 0 Reputation points
2024-10-09T01:20:52.5166667+00:00

I want to deploy a function app on Azure that would periodically pull updates from a website and augments a MongoDB collection hosted on Atlas.

The python v2 code that I have written for this purpose works fine on my local machine where it triggered based on my machine's time. However, when I deploy to Azure, I expected the function app to be triggered in UTC time but it is not happening.

When I tried the following CRON expression instead of a UTC time mention, the deployed timer trigger gets fired sometimes but not always. It is hard to figure out what is missing and how to fix it. Any help or insights would be greatly appreciated.

"* *\5 * * * * *"
app = func.FunctionApp()
@app.function_name(name="mytimer")
@app.timer_trigger(schedule="* 40 16 * * * *", 
             arg_name="mytimer")
def pull_function(mytimer: func.TimerRequest) -> None:
    if mytimer.past_due:
        logging.info('The timer is past due!')
    logging.info('Python timer trigger function is invoked')

    logging.info("Gonna fetch docs")
    
    #code logic will follow from here

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JananiRamesh-MSFT 29,261 Reputation points
    2024-10-09T02:37:44.4333333+00:00

    @Devi Thanks for reaching out. It seems that you are trying to deploy a timer-triggered Azure Function that periodically pulls updates from a website and augments a MongoDB collection hosted on Atlas. The CRON expression you provided ("* *\5 * * * * *") is not valid. The correct format for a CRON expression is as follows the following CRON expression triggers the function every 5 minutes:

    0 */5 * * * *
    

    In this expression, the first field (seconds) is set to 0, which means that the function is triggered at the start of each minute. The second field (minutes) is set to */5, which means that the function is triggered every 5 minutes. The remaining fields are set to * (wildcard), which means that the function is triggered every day of every month.

    Regarding the issue with the function not being triggered in UTC time, by default, Azure Functions use UTC. If your function is not triggering as expected, double-check the time zone settings in your function app configuration. You can explicitly set the time zone by adding the WEBSITE_TIME_ZONE application setting in the Azure portal.

    do try and let me know incase of further queries, I would be happy to assist you.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.