4

Does the durable function awake until activity invoked?

I'm about the implement scheduler, and instead use other library such Hangfire or Quartz. i want to implement durable function that will serve as a scheduler. And my missing piece is, what happen in the function? does the function got shout until next activity invocation? each one is called execution?

[FunctionName("SchedulerRouter")]
public static async Task<HttpResponseMessage> HttpStart(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")]HttpRequestMessage req,
    [OrchestrationClient]DurableOrchestrationClient starter, ILogger log)
{
    var data = await req.Content.ReadAsAsync<JObject>();
    var instanceId = await starter.StartNewAsync(FunctionsConsts.MAIN_DURABLE_SCHEDULER_NAME, data);
    return starter.CreateCheckStatusResponse(req, instanceId);
}
kevinj
  • 255
  • 2
  • 11
Avi Siboni
  • 686
  • 7
  • 16
  • 2
    Have you read https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-overview ? – mjwills Sep 01 '19 at 12:12
  • Yes, but im not sure what is going under the hood...does it keep on the state? if so that's mean the function is still running? if not, what's keeping the state? – Avi Siboni Sep 01 '19 at 13:26
  • 2
    It's explained in this page: https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-concepts#the-technology – CSharpRocks Sep 01 '19 at 13:46

2 Answers2

6

Looks like you are confusing execution time with Max inactivity time is Azure functions:

Durable function is just related to the maximum execution time of a single call. For "out of the box" functions, that timeout is 10min, for durable functions this limitation gets removed. It also introduces support for stateful executions, which means following calls to the same function can share local variables and static members. This is an extension of the "out of the box" functions patterns which needs some additional boiler plate code to make everything working as expected. More details here: https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-overview

Durable functions and normal functions share the same billing pattern, so cold starts will happen on durable functions as well especially when running in a consumption plan.

Azure functions running in a consumption plan will shutdown during a period of inactivity , and then reallocated and restarted when a new request arrives, this is called: Cold Start. You can mitigate this, building a timer trigger function which awakes your function every 5 to 10 min. But, you will still incurr in cold starts from time to time if your host gets up or down scaled automatically by Azure. If you want to completely remove the chance of cold starts you will have to move to an App service plan. As a side note, Function apps in Azure are stateless by design, and you should implement your logic with this requirement in mind.

kevinj
  • 255
  • 2
  • 11
  • Thank you @kevinj for your answer :) i'm familiar with cold start, i just wanted to figure what's happening in durable function under the hood. does it really shutdown until the next execution? or it keep cold start as you said..yeha i got a bit of confusion – Avi Siboni Sep 02 '19 at 08:50
  • @avisiboni, i updated my answer with some more details and a reference to the MSDN. – kevinj Sep 02 '19 at 12:49
  • Great! I am glad everything is sorted for you now. – kevinj Sep 02 '19 at 14:59
1

Did you looked into time triggers for AZ Functions? Maybe it is more soutable for you use case. Basically a CRON time tigger that invokes the function according the CRON setting.

The portal example for time trigger

Zsolt Bendes
  • 2,219
  • 12
  • 18