Skip to content

Latest commit

 

History

History

DurableTask.Samples

README.md

DurableTask.Samples

This project contains core sample orchestrations demonstrating fundamental patterns of the Durable Task Framework using the Azure Storage backend.

Prerequisites

  • .NET Framework 4.8 or later
  • Azure Storage Emulator (Azurite) or Azure Storage account

Configuration

Configure the connection string in App.config:

<appSettings>
  <add key="StorageConnectionString" value="UseDevelopmentStorage=true" />
  <add key="taskHubName" value="SamplesHub" />
</appSettings>

For Azure Storage, replace UseDevelopmentStorage=true with your connection string (if not using the emulator):

DefaultEndpointsProtocol=https;AccountName=...;AccountKey=...

Running the Samples

1. Create the Task Hub (first time only)

DurableTask.Samples.exe -c

2. Start an Orchestration

DurableTask.Samples.exe -s <OrchestrationName> [-p <parameters>]

The worker automatically starts and waits for the orchestration to complete.

Available Samples

Each sample's full source is linked below. For deeper explanations of the patterns they demonstrate, see the DTFx documentation.

Greetings

Two activities run in sequence: GetUserTask produces a name, then SendGreetingTask greets it. A minimal introduction to orchestrations and activities.

Greetings2

A variation that races the GetUserTask activity against a durable timer using Task.WhenAny, so the orchestration proceeds when the user responds or the timeout elapses, whichever comes first. The parameter is the timeout in seconds.

Cron

Runs CronTask on a schedule, using CreateTimer to wait between runs. The sample loops a fixed number of times (currently 4) and then returns — it is not an eternal orchestration and does not use ContinueAsNew. The parameter is a cron expression (via NCrontab) and is optional (it falls back to a fixed interval when omitted).

Average

A fan-out/fan-in pattern that splits a numeric range into chunks, computes a partial sum for each chunk in parallel via ComputeSumTask, then aggregates the results into an average. Parameters are <start> <end> <step>.

ErrorHandling

Demonstrates exception handling with try/catch around activities and a compensating CleanupTask when an activity fails.

Signal

Demonstrates external events using the OnEvent + TaskCompletionSource pattern: the orchestration waits for an external signal and then sends a greeting with the signaled value.

To raise an event to a running instance:

DurableTask.Samples.exe -n <eventName> -i <instanceId> -p <eventData>

You can also start an instance and raise its first event in one step with the SignalAndRaise sample:

  • Run: DurableTask.Samples.exe -s SignalAndRaise -n <eventName> -p <eventData>

SumOfSquares

A recursive fan-out/fan-in example that walks a nested JSON array (BagofNumbers.json), squaring integers via SumOfSquaresTask and recursing into nested arrays as sub-orchestrations.

Command Line Options

Option Description
-c Create the task hub (required on first run)
-s <name> Start the specified orchestration
-p <params> Parameters to pass to the orchestration
-i <id> Instance ID (auto-generated if not specified)
-n <name> Event name for raising events
-w Skip the worker (useful when worker runs separately)

Additional Resources