Java Azure function Timer Trigger configuration ( for different environments dev/stg/prod )

Maciej Bąk 46 Reputation points
2023-01-19T10:12:15.01+00:00

Hi,

I have Timer trigger:

@FunctionName("Refresh-Data-Daily-Services")public void dailyServices(        @TimerTrigger(                name = "timerInfo",                schedule = "0 0 23 * * *" // At 23:00        ) String timerInfo,        final ExecutionContext context)

but schedule is hardcoded in code. Is it possible to configure it ? So I could set it in Settings/Configuration/Application Settings ? I need different timer triggers for different environments.

Thanks!

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

Accepted answer
  1. MughundhanRaveendran-MSFT 12,481 Reputation points
    2023-01-20T09:31:36.9+00:00

    @Maciej Bąk

    Thanks for reaching out to Q&A forum.

    Yes. You can set the expression in an app setting and refer to it using % signs. For instance, if you have a setting called CRON_EXPRESSION:

    @FunctionName("Refresh-Data-Daily-Services")public void dailyServices( @TimerTrigger( name = "timerInfo", schedule = "%CRON_EXPRESSION%" ) String timerInfo, final ExecutionContext context)

    Reference : https://github.com/Azure/azure-functions-host/issues/1934

    Hope this helps! Feel free to reach out to me if you have any queries or concerns.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.