Azure Function App : Run a function at 2AM local time for three different time zone AUS

Harshal Sonparote 1 Reputation point
2023-12-01T11:02:04.9633333+00:00

HI Team ,

I have a requirement to run one Azure Function at 2AM local time for three different regions. I do not want to end up duplicating function for three different regions. Can you please suggest appropriate solution to this scenario,

Regards,

Harshal

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

2 answers

Sort by: Most helpful
  1. MayankBargali-MSFT 70,936 Reputation points Moderator
    2023-12-01T12:54:49.17+00:00

    @Harshal Sonparote Thanks for reaching out.

    As only one CRON expression can be used for a single timer trigger in Azure Functions.

    To run the same function app at different local times for different regions, you will need to create multiple timer triggers with different CRON expressions, each set to the appropriate local time for the region.

    In case if you want to manage the code at one place and don't want to copy/paste in all code then you can create one HTTP trigger/different method which has your main logic and other three timer trigger that run with different CORN expression. Now in your individual timer trigger you need to need to make the HTTP call/other method to trigger your main logic/function.

    0 comments No comments

  2. Sander van de Velde | MVP 36,761 Reputation points MVP Volunteer Moderator
    2023-12-01T13:08:32.3266667+00:00

    Hello @Harshal Sonparote ,

    welcome to this moderated Azure community forum.

    I expect you are using a timer-triggered Azure Function.

    The function can be set to only one (repeating) point in time (like "0 30 9 * * *" = 9:30 AM every day) or multiple times if there is a pattern (like "0 0 9-17 * * *" = once every hour from 9 AM to 5 PM).

    If the three regions all have the same timespan difference, you a in luck.

    Otherwise, you need to register multiple functions.

    But that does not mean you register the same code multiple times!

    You could write the actual code once and use it multiple times if you run it within the same WebApp:

    [Function(nameof(TimerFunction))
    public static void RunA([TimerTrigger("0 30 9 * * *")] TimerInfo timerInfo, FunctionContext context)
    {
        ExecuteLogic();
    }
    
    Function(nameof(TimerFunction))  
    public static void RunB([TimerTrigger("0 30 11 * * *")] TimerInfo timerInfo, FunctionContext context)  
    {
        ExecuteLogic();  
    }
    
    Function(nameof(TimerFunction))  
    public static void RunC([TimerTrigger("0 30 15 * * *")] TimerInfo timerInfo, FunctionContext context)  
    {   
       ExecuteLogic();  
    }
    

    Keep in mind this Function logic is UTC timestamp by default.

    Check the documentation regarding time zones.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    0 comments No comments

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.