1

I have requirement to develop Azure Function App which is able to run on schedule also when needed User can manually run it. Please share the view how I can implement it.

Swap
  • 45
  • 4

2 Answers2

1

For this requirement, I don't think we can do it in one function. You need to create a HTTP trigger function and write the code in it. And create another timer trigger function, request the http trigger function url in the timer trigger function.

When you want to run it manually, request the http trigger function url. And the timer trigger function will also be scheduled to run according to the cron expression you specified.

Hury Shen
  • 14,948
  • 1
  • 9
  • 18
  • How binding can use to implement it – Swap Sep 25 '20 at 07:30
  • Hi @Swap I'm not so clear about your question about "how binding". My solution is to create two function in your function app. One is http trigger(with your main body of code), the other is timer trigger(with one line of request the http trigger url). It has nothing to do with binding. – Hury Shen Sep 25 '20 at 07:33
  • @Swap You just need to write code like `HttpClient client = new HttpClient(); var content = new FormUrlEncodedContent(your request body); client.PostAsync("httptrigger url", content);` in the timer trigger function. – Hury Shen Sep 25 '20 at 07:38
  • @HuryShen ... making sure not to re-instantiate `HttpClient` every single time, and instead keeping it a static member of the encapsulating class https://www.youtube.com/watch?v=ym7kNYOAVx0&t=1s – Alex Gordon Sep 27 '20 at 11:27
0

@Swap you should read up on TimerTriggers here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=csharp#example

A TimerTrigger allows you to define a repeatable event which you can also run manually from the Azure portal.

It sounds like you might need a better solution altogether as Hury suggested. You might want to read up on Logic Apps which can be used as a web job for a standard HttpTrigger.

Creating a HttpTrigger function allows you to manually, or programmatically, trigger the method. You can use LogicApps to trigger the same function on a schedule.

I think there might be several ways to help you...

Maybe if you provide more detail on what you are trying accomplish?

Mark
  • 1
  • 2