0
0
Azurecloud~5 mins

Durable Functions for workflows in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Durable Functions help you run tasks that take a long time or need to happen in order. They keep track of progress even if the computer restarts. This makes sure your work finishes without losing data.
When you want to run a process that has many steps, like ordering and shipping a product.
When you need to wait for a long time between steps, like waiting for a user to approve something.
When you want to retry a task if it fails without losing progress.
When you want to run multiple tasks at the same time and then combine their results.
When you want to keep track of a process that might stop and start again automatically.
Config File - function.json
function.json
{
  "bindings": [
    {
      "name": "context",
      "type": "orchestrationTrigger",
      "direction": "in"
    }
  ]
}

This file tells Azure Functions that this is an orchestration function. The orchestrationTrigger means it controls the workflow steps. The context is used to manage the workflow state and call other functions.

Commands
Create a new Azure Functions project using .NET runtime to build Durable Functions.
Terminal
func init DurableFunctionApp --worker-runtime dotnet
Expected OutputExpected
The project 'DurableFunctionApp' has been created.
--worker-runtime - Specifies the language runtime for the function app.
Add a new Durable Functions orchestration named OrderWorkflow to define the workflow steps.
Terminal
func new --name OrderWorkflow --template "Durable Functions Orchestration"
Expected OutputExpected
Created new Durable Functions Orchestration 'OrderWorkflow'.
--template - Specifies the function template to use.
Start the OrderWorkflow orchestration with input data containing order ID 123.
Terminal
func start-new OrderWorkflow --input "{\"orderId\":123}"
Expected OutputExpected
Started orchestration with instance ID: 12345abcde
Check the current status of the running workflow using its instance ID.
Terminal
func durable get-status 12345abcde
Expected OutputExpected
{ "runtimeStatus": "Running", "input": {"orderId":123}, "output": null }
Key Concept

If you remember nothing else from this pattern, remember: Durable Functions keep track of your workflow steps and state automatically, so your long or complex tasks never lose progress.

Common Mistakes
Not using the orchestration trigger binding in the function.json file.
Without the orchestration trigger, Azure won't treat the function as a workflow controller, so it won't manage state or call activity functions properly.
Always set the function.json binding type to 'orchestrationTrigger' for orchestration functions.
Starting the orchestration without providing required input data.
The workflow may fail or behave unexpectedly if it expects input but none is given.
Always provide the necessary input JSON when starting the orchestration.
Checking status with a wrong or missing instance ID.
You won't get the correct workflow status, making it hard to track progress.
Save the instance ID returned when starting the orchestration and use it to check status.
Summary
Initialize a new Azure Functions project with Durable Functions support.
Create an orchestration function that defines the workflow steps.
Start the orchestration with input data to run the workflow.
Check the workflow status anytime using the orchestration instance ID.