Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial push for adding orchestration reuse ID #258

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
52 changes: 52 additions & 0 deletions src/Abstractions/OrchestrationOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.DurableTask;

/// <summary>
/// Enum describing the runtime status of the orchestration.
/// </summary>
public enum OrchestrationRuntimeStatus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will need to have type-forwarding from this type in the client package.

{
/// <summary>
/// The orchestration started running.
/// </summary>
Running,

/// <summary>
/// The orchestration completed normally.
/// </summary>
Completed,

/// <summary>
/// The orchestration is transitioning into a new instance.
/// </summary>
[Obsolete("The ContinuedAsNew status is obsolete and exists only for compatibility reasons.")]
ContinuedAsNew,

/// <summary>
/// The orchestration completed with an unhandled exception.
/// </summary>
Failed,

/// <summary>
/// The orchestration canceled gracefully.
/// </summary>
[Obsolete("The Canceled status is not currently used and exists only for compatibility reasons.")]
Canceled,

/// <summary>
/// The orchestration was abruptly terminated via a management API call.
/// </summary>
Terminated,

/// <summary>
/// The orchestration was scheduled but hasn't started running.
/// </summary>
Pending,

/// <summary>
/// The orchestration has been suspended.
/// </summary>
Suspended,
}
5 changes: 4 additions & 1 deletion src/Abstractions/TaskOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,7 @@ public SubOrchestrationOptions(TaskOptions options, string? instanceId = null)
/// 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);
/// <param name="OrchestrationIdReusePolicy">The orchestration reuse policy. This allows for the reuse of an instance ID
/// if the instance ID referenced is in any of the states supplied in this parameter.</param>
public record StartOrchestrationOptions(string? InstanceId = null, DateTimeOffset? StartAt = null,
OrchestrationRuntimeStatus[]? OrchestrationIdReusePolicy = null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we wrap this in a type: OrchestrationIdReuse, so we can have helpers:

OrchestrationIdReuse.IfTerminal; // has all terminal statuses included.
OrchestrationIdReuse.Always; // has all statuses included.
OrchestrationIdReuse.IfStatus(params OrchestrationRuntimeStatus[] statuses);
OrchestrationIdReuse.IfStatus(IEnumerable<OrchestrationRuntimeStatus> statuses);
OrchestrationIdReuse.Never; // equal to default.

1 change: 1 addition & 0 deletions src/Client/Grpc/GrpcDurableTaskClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public override async Task<string> ScheduleNewOrchestrationInstanceAsync(
Version = orchestratorName.Version,
InstanceId = options?.InstanceId ?? Guid.NewGuid().ToString("N"),
Input = this.DataConverter.Serialize(input),
OrchestrationIdReusePolicy = { },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to map this from options correct?

};

DateTimeOffset? startAt = options?.StartAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ The client is responsible for interacting with orchestrations from outside the w
<EnableStyleCop>true</EnableStyleCop>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these packages needed for?

<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
</ItemGroup>

<PropertyGroup>
<!-- We are still working on this package for entities preview. -->
<VersionPrefix>1.0.5</VersionPrefix>
Expand All @@ -17,11 +22,13 @@ The client is responsible for interacting with orchestrations from outside the w

<ItemGroup>
<ProjectReference Include="../Core/Client.csproj" />
<ProjectReference Include="../../Grpc/Grpc.csproj" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be depending on gRPC

</ItemGroup>

<ItemGroup>
<SharedSection Include="Core" />
<SharedSection Include="DependencyInjection" />
<SharedSection Include="Grpc" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ public override async Task<string> ScheduleNewOrchestrationInstanceAsync(
{
cancellation.ThrowIfCancellationRequested();
string instanceId = options?.InstanceId ?? Guid.NewGuid().ToString("N");
OrchestrationStatus[] runtimeStates = Array.Empty<OrchestrationStatus>();

// Convert from DurableTask.OrchestrationRuntimeStatus to DurableTask.Core.OrchestrationRuntimeStatus
if (options?.OrchestrationIdReusePolicy != null)
{
runtimeStates = new OrchestrationStatus[options.OrchestrationIdReusePolicy.Length];
for (int i = 0; i < options.OrchestrationIdReusePolicy.Length; i++)
{
runtimeStates[i] = ConvertState(options.OrchestrationIdReusePolicy[i]);
}
}

OrchestrationInstance instance = new()
{
InstanceId = instanceId,
Expand All @@ -157,7 +169,7 @@ public override async Task<string> ScheduleNewOrchestrationInstanceAsync(
},
};

await this.Client.CreateTaskOrchestrationAsync(message);
await this.Client.CreateTaskOrchestrationAsync(message, runtimeStates);
return instanceId;
}

Expand Down Expand Up @@ -219,6 +231,28 @@ public override async Task<OrchestrationMetadata> WaitForInstanceStartAsync(
}
}

// Converts from DurableTask.OrchestrationRuntimeStatus to OrchestrationStatus for policy reuse.
static OrchestrationStatus ConvertState(DurableTask.OrchestrationRuntimeStatus state)
{
switch (state)
{
case DurableTask.OrchestrationRuntimeStatus.Running:
return OrchestrationStatus.Running;
case DurableTask.OrchestrationRuntimeStatus.Completed:
return OrchestrationStatus.Completed;
case DurableTask.OrchestrationRuntimeStatus.Failed:
return OrchestrationStatus.Failed;
case DurableTask.OrchestrationRuntimeStatus.Terminated:
return OrchestrationStatus.Terminated;
case DurableTask.OrchestrationRuntimeStatus.Pending:
return OrchestrationStatus.Pending;
case DurableTask.OrchestrationRuntimeStatus.Suspended:
return OrchestrationStatus.Suspended;
default:
return OrchestrationStatus.Terminated;
}
}

[return: NotNullIfNotNull("state")]
OrchestrationMetadata? ToMetadata(Core.OrchestrationState? state, bool getInputsAndOutputs)
{
Expand Down
Loading