Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<ItemGroup>
<PackageVersion Include="Microsoft.Azure.DurableTask.Core" Version="3.0.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.2.2" />
<PackageVersion Include="Microsoft.DurableTask.Sidecar" Version="1.1.2" />
</ItemGroup>

<!-- Grpc / Protobuf Packages -->
Expand Down Expand Up @@ -77,6 +76,7 @@
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="System.Text.Json" Version="6.0.10" />
<PackageVersion Include="System.Collections.Immutable" Version="6.0.1" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/Abstractions/Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="System.Collections.Immutable"/>
</ItemGroup>

<ItemGroup>
Expand Down
214 changes: 111 additions & 103 deletions src/Abstractions/TaskOptions.cs
Original file line number Diff line number Diff line change
@@ -1,103 +1,111 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.DurableTask;

/// <summary>
/// Options that can be used to control the behavior of orchestrator task execution.
/// </summary>
public record TaskOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="TaskOptions"/> class.
/// </summary>
/// <param name="retry">The task retry options.</param>
public TaskOptions(TaskRetryOptions? retry = null)
{
this.Retry = retry;
}

/// <summary>
/// Gets the task retry options.
/// </summary>
public TaskRetryOptions? Retry { get; init; }

/// <summary>
/// Returns a new <see cref="TaskOptions" /> from the provided <see cref="RetryPolicy" />.
/// </summary>
/// <param name="policy">The policy to convert from.</param>
/// <returns>A <see cref="TaskOptions" /> built from the policy.</returns>
public static TaskOptions FromRetryPolicy(RetryPolicy policy) => new(policy);

/// <summary>
/// Returns a new <see cref="TaskOptions" /> from the provided <see cref="AsyncRetryHandler" />.
/// </summary>
/// <param name="handler">The handler to convert from.</param>
/// <returns>A <see cref="TaskOptions" /> built from the handler.</returns>
public static TaskOptions FromRetryHandler(AsyncRetryHandler handler) => new(handler);

/// <summary>
/// Returns a new <see cref="TaskOptions" /> from the provided <see cref="RetryHandler" />.
/// </summary>
/// <param name="handler">The handler to convert from.</param>
/// <returns>A <see cref="TaskOptions" /> built from the handler.</returns>
public static TaskOptions FromRetryHandler(RetryHandler handler) => new(handler);

/// <summary>
/// Returns a new <see cref="SubOrchestrationOptions" /> with the provided instance ID. This can be used when
/// starting a new sub-orchestration to specify the instance ID.
/// </summary>
/// <param name="instanceId">The instance ID to use.</param>
/// <returns>A new <see cref="SubOrchestrationOptions" />.</returns>
public SubOrchestrationOptions WithInstanceId(string instanceId) => new(this, instanceId);
}

/// <summary>
/// Options that can be used to control the behavior of orchestrator task execution. This derived type can be used to
/// supply extra options for orchestrations.
/// </summary>
public record SubOrchestrationOptions : TaskOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="SubOrchestrationOptions"/> class.
/// </summary>
/// <param name="retry">The task retry options.</param>
/// <param name="instanceId">The orchestration instance ID.</param>
public SubOrchestrationOptions(TaskRetryOptions? retry = null, string? instanceId = null)
: base(retry)
{
this.InstanceId = instanceId;
}

/// <summary>
/// Initializes a new instance of the <see cref="SubOrchestrationOptions"/> class.
/// </summary>
/// <param name="options">The task options to wrap.</param>
/// <param name="instanceId">The orchestration instance ID.</param>
public SubOrchestrationOptions(TaskOptions options, string? instanceId = null)
: base(options)
{
this.InstanceId = instanceId;
if (instanceId is null && options is SubOrchestrationOptions derived)
{
this.InstanceId = derived.InstanceId;
}
}

/// <summary>
/// Gets the orchestration instance ID.
/// </summary>
public string? InstanceId { get; init; }
}

/// <summary>
/// Options for submitting new orchestrations via the client.
/// </summary>
/// <param name="InstanceId">
/// The unique ID of the orchestration instance to schedule. If not specified, a new GUID value is used.
/// </param>
/// <param name="StartAt">
/// The time when the orchestration instance should start executing. If not specified or if a date-time in the past
/// is specified, the orchestration instance will be scheduled immediately.
/// </param>
public record StartOrchestrationOptions(string? InstanceId = null, DateTimeOffset? StartAt = null);
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Collections.Immutable;

namespace Microsoft.DurableTask;

/// <summary>
/// Options that can be used to control the behavior of orchestrator task execution.
/// </summary>
public record TaskOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="TaskOptions"/> class.
/// </summary>
/// <param name="retry">The task retry options.</param>
public TaskOptions(TaskRetryOptions? retry = null)
{
this.Retry = retry;
}

/// <summary>
/// Gets the task retry options.
/// </summary>
public TaskRetryOptions? Retry { get; init; }

/// <summary>
/// Returns a new <see cref="TaskOptions" /> from the provided <see cref="RetryPolicy" />.
/// </summary>
/// <param name="policy">The policy to convert from.</param>
/// <returns>A <see cref="TaskOptions" /> built from the policy.</returns>
public static TaskOptions FromRetryPolicy(RetryPolicy policy) => new(policy);

/// <summary>
/// Returns a new <see cref="TaskOptions" /> from the provided <see cref="AsyncRetryHandler" />.
/// </summary>
/// <param name="handler">The handler to convert from.</param>
/// <returns>A <see cref="TaskOptions" /> built from the handler.</returns>
public static TaskOptions FromRetryHandler(AsyncRetryHandler handler) => new(handler);

/// <summary>
/// Returns a new <see cref="TaskOptions" /> from the provided <see cref="RetryHandler" />.
/// </summary>
/// <param name="handler">The handler to convert from.</param>
/// <returns>A <see cref="TaskOptions" /> built from the handler.</returns>
public static TaskOptions FromRetryHandler(RetryHandler handler) => new(handler);

/// <summary>
/// Returns a new <see cref="SubOrchestrationOptions" /> with the provided instance ID. This can be used when
/// starting a new sub-orchestration to specify the instance ID.
/// </summary>
/// <param name="instanceId">The instance ID to use.</param>
/// <returns>A new <see cref="SubOrchestrationOptions" />.</returns>
public SubOrchestrationOptions WithInstanceId(string instanceId) => new(this, instanceId);
}

/// <summary>
/// Options that can be used to control the behavior of orchestrator task execution. This derived type can be used to
/// supply extra options for orchestrations.
/// </summary>
public record SubOrchestrationOptions : TaskOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="SubOrchestrationOptions"/> class.
/// </summary>
/// <param name="retry">The task retry options.</param>
/// <param name="instanceId">The orchestration instance ID.</param>
public SubOrchestrationOptions(TaskRetryOptions? retry = null, string? instanceId = null)
: base(retry)
{
this.InstanceId = instanceId;
}

/// <summary>
/// Initializes a new instance of the <see cref="SubOrchestrationOptions"/> class.
/// </summary>
/// <param name="options">The task options to wrap.</param>
/// <param name="instanceId">The orchestration instance ID.</param>
public SubOrchestrationOptions(TaskOptions options, string? instanceId = null)
: base(options)
{
this.InstanceId = instanceId;
if (instanceId is null && options is SubOrchestrationOptions derived)
{
this.InstanceId = derived.InstanceId;
}
}

/// <summary>
/// Gets the orchestration instance ID.
/// </summary>
public string? InstanceId { get; init; }
}

/// <summary>
/// Options for submitting new orchestrations via the client.
/// </summary>
/// <param name="InstanceId">
/// The unique ID of the orchestration instance to schedule. If not specified, a new GUID value is used.
/// </param>
/// <param name="StartAt">
/// The time when the orchestration instance should start executing. If not specified or if a date-time in the past
/// is specified, the orchestration instance will be scheduled immediately.
/// </param>
public record StartOrchestrationOptions(string? InstanceId = null, DateTimeOffset? StartAt = null)
{
/// <summary>
/// Gets the tags to associate with the orchestration instance. Tags are key-value pairs that can be used.
/// </summary>
public IReadOnlyDictionary<string, string> Tags { get; init; } = ImmutableDictionary.Create<string, string>();
}
Loading
Loading