Skip to content

Update Azure Functions docs with examples for use of Durable Task Scheduler #214

@philliphoff

Description

@philliphoff

dotnet/aspire#13711 adds resources related to the Durable Task Scheduler (DTS) to the Azure Functions host library, which allow customers to start the DTS emulator (or connect to an existing Azure resource) for use with Azure Functions applications.

There is an existing doc for use of Azure Functions within Aspire; with this PR the doc should be updated with similar examples of using Azure Functions with DTS.

Under Hosting integration, a new section could be added similar to:

Durable Task Scheduler (Durable Functions)

The Azure Functions hosting library also provides resource APIs for using the Durable Task Scheduler (DTS) with Durable Functions.

In the AppHost.cs file of AppHost, add a Scheduler resource, create one or more Task Hubs, and pass the connection string and hub name to your Functions project:

using Aspire.Hosting;
using Aspire.Hosting.Azure;
using Aspire.Hosting.Azure.Functions;

var builder = DistributedApplication.CreateBuilder(args);

var storage = builder.AddAzureStorage("storage").RunAsEmulator();

var scheduler = builder.AddDurableTaskScheduler("scheduler")
    .RunAsEmulator();

var taskHub = scheduler.AddTaskHub("taskhub");

builder.AddAzureFunctionsProject<Projects.Company_FunctionApp>("funcapp")
    .WithHostStorage(storage)
    .WithEnvironment("DURABLE_TASK_SCHEDULER_CONNECTION_STRING", scheduler)
    .WithEnvironment("TASKHUB_NAME", taskHub.Resource.TaskHubName);

builder.Build().Run();

Use the DTS emulator

RunAsEmulator() starts a local container running the Durable Task Scheduler emulator.

When a Scheduler runs as an emulator, Aspire automatically provides:

  • A "Scheduler Dashboard" URL for the scheduler resource.
  • A "Task Hub Dashboard" URL for each Task Hub resource.
  • A DTS_TASK_HUB_NAMES environment variable on the emulator container listing the Task Hub names associated with that scheduler.

Use an existing Scheduler

If you already have a Scheduler instance, configure the resource using its connection string:

var schedulerConnectionString = builder.AddParameter(
    "dts-connection-string",
    "Endpoint=https://existing-scheduler.durabletask.io;Authentication=DefaultAzure");

var scheduler = builder.AddDurableTaskScheduler("scheduler")
    .RunAsExisting(schedulerConnectionString);

var taskHubName = builder.AddParameter("taskhub-name", "mytaskhub");
var taskHub = scheduler.AddTaskHub("taskhub").WithTaskHubName(taskHubName);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions