Calling functions from other functions in Azure servless function app - azure

I have a timer function that runs by itself once per minute.
Is it possible to invoke this function from another type of function if I want to call it at an arbitrary time (not on its cron schedule).
From:
An orchestrator function?
An activity function?
Also, it is it possible to call an orchestrator directly from a an activity function? I have heard that you can do "sub orchestrations" from an orchestrator. But what about directly from an activity function.

You cannot call the Time Trigger Function, but one thing you can do is extract the logic to a class library and share it with a Http Trigger that function that will be running in the same Azure Function App as the time trigger one.
About the Durable part, it's been a while since the last time I worked with that, but as far as I know, the orchestrator can call sub orchestrators and activities.

Related

Cloud functions: call a second function when the first has finished

How can I execute a second cloud function when the first has finished?
I'd like to call a new cloud function, not a normal js function, in order to reduce each function execution time. Also I need a serial execution, not parallell (the second function queries data updated by the first)
To solve your issue, you need an orchestrator. Run a pipeline, call your first functions, then call the second functions (then whatever!!)
My preferred is https://cloud.google.com/workflows/docs/overview: serverless, cheap, perfect for working with Cloud Functions
Or you can use the heavy and expensive Cloud Composer

How to stop replay activity in azure durable functions?

I created 1 activity function and calling it from orchestrator function using powershell commandlet Invoke-DurableActivity. But when I executed the orchestrator function I'm seeing that the code running asynchronous and replay activity causing code to re-run. How can I avoid this re-run as we don't need it.
The re-run is part of the design of the framework. The good news is, once the activity finishes, The orchestrator will check internally for the state (result of the activity) and will move to the next step of your workflow.

Is the orchestrator client function reliable?

I am new to azure durable functions. According to documents that the orchestrator functions are reliable. But I am wondering if the the starter function is reliable. Suppose that I have a http-trigger orchestrator functions. I guess when durable function framework (or something run in backend) detects that an http request matches a orchestrator function, it starts the starter function to trigger the orchestrator function. I am wondering where the starter function runs, a VM? Can the VM fail? I cannot find much doc on msdn.
Orchestrator functions reliably maintain their execution state by using the event sourcing design pattern. Instead of directly storing the current state of an orchestration, the Durable Task Framework uses an append-only store to record the full series of actions the function orchestration takes. An append-only store has many benefits compared to "dumping" the full runtime state. Benefits include increased performance, scalability, and responsiveness. You also get eventual consistency for transactional data and full audit trails and history. The audit trails support reliable compensating actions.
Durable Functions uses event sourcing transparently. Behind the scenes, the await (C#) or yield (JavaScript) operator in an orchestrator function yields control of the orchestrator thread back to the Durable Task Framework dispatcher. The dispatcher then commits any new actions that the orchestrator function scheduled (such as calling one or more child functions or scheduling a durable timer) to storage. The transparent commit action appends to the execution history of the orchestration instance. The history is stored in a storage table. The commit action then adds messages to a queue to schedule the actual work. At this point, the orchestrator function can be unloaded from memory.
When an orchestration function is given more work to do (for example, a response message is received or a durable timer expires), the orchestrator wakes up and re-executes the entire function from the start to rebuild the local state. During the replay, if the code tries to call a function (or do any other async work), the Durable Task Framework consults the execution history of the current orchestration. If it finds that the activity function has already executed and yielded a result, it replays that function's result and the orchestrator code continues to run. Replay continues until the function code is finished or until it has scheduled new async work.
Offcial doc

Azure Function V1 Call another azure function from current azure function

I am using Azure Function V1 c#. I have a time triggered azure function which is checking for some data in my database every second. If the data is found I want to perform some operation on it. This operation can take 30 seconds to 5 minutes depending on the operations happening on it.
When I my time triggered function gets data and starts performing operation on it. Time triggered function is not getting executed again until first operation is completed. So, even if time triggered function is scheduled to be executed every second, it is not getting executed for next 30 seconds if the operation in previous iteration took 30 seconds. How can I solve it?
Can I call some other azure function from current time triggered function that can take care of that 30 sec. running operation and my time triggered function runs smoothly every second?
How can I call another azure function (Custom Function) from current time triggered function?
Thanks,
You may need to consider logic apps for this scenario. Logic Apps are serverless workflow offering from Azure. Use recurrence trigger to schedule the job (http call) and it will trigger the azure function regardless.
https://learn.microsoft.com/en-us/azure/connectors/connectors-native-recurrence
If you want to trigger any external function you may use httpclient.
Azure Functions call http post inside function

Azure: Call one functionapp from another functionapp

have two function app (httptrigger) in one of azure function apps project.
PUT
DELETE
In certain condition, would like to call DELETE function app from PUT function app.
Is it possible to get directly RUN of DELETE function app as both are resides in same function app project ?
I wouldn't recommend trying to call the actual function directly, but you can certainly refactor the DELETE functionality into a normal method and then call that from both the DELETE and PUT functions.
There is a few ways to call a function from the function:
HTTP request - it's simple, execute a normal HTTP request to your second function. It's not recommended, because it extends function execution time and generates a few additional problems, such as the possibility of receiving a timeout, the unavailability of the service and others.
Storage queues - make communication through queues (recommended), e.g. the first function (in your situation: "PUT function) can insert a message to the queue and the second function ("DELETE function") can listen on this queue and process a message.
Azure Durable Functions - this extensions allows to create rich, easy-to-understand workflows that are cheap and reliable. Another advantage is that they can retain their own internal state, which can be used for communication between functions.
Read more about cross function communication here.

Resources