Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.0.0

- Added `SuspendInstanceAsync` and `ResumeInstanceAsync` to `DurableTaskClient`.

## v1.0.0-rc.1

### Included Packages
Expand Down
27 changes: 27 additions & 0 deletions src/Client/Core/DurableTaskClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,33 @@ public abstract Task<string> ScheduleNewOrchestrationInstanceAsync(
/// <returns>A task that completes when the terminate message is enqueued.</returns>
public abstract Task TerminateAsync(string instanceId, object? output);

/// <summary>
/// Suspends an orchestration instance, halting processing of it until <see cref="ResumeInstanceAsync" /> is used
/// to resume the orchestration.
/// </summary>
/// <param name="instanceId">The instance ID of the orchestration to suspend.</param>
/// <param name="reason">The optional suspension reason.</param>
/// <param name="cancellation">
/// A <see cref="CancellationToken"/> that can be used to cancel the suspend operation. Note, cancelling this token
/// does <b>not</b> resume the orchestration if suspend was successful.
/// </param>
/// <returns>A task that completes when the suspend has been committed to the backend.</returns>
public abstract Task SuspendInstanceAsync(
string instanceId, string? reason = null, CancellationToken cancellation = default);

/// <summary>
/// Resumes an orchestration instance that was suspended via <see cref="SuspendInstanceAsync" />.
/// </summary>
/// <param name="instanceId">The instance ID of the orchestration to resume.</param>
/// <param name="reason">The optional resume reason.</param>
/// <param name="cancellation">
/// A <see cref="CancellationToken"/> that can be used to cancel the resume operation. Note, cancelling this token
/// does <b>not</b> re-suspend the orchestration if resume was successful.
/// </param>
/// <returns>A task that completes when the resume has been committed to the backend.</returns>
public abstract Task ResumeInstanceAsync(
string instanceId, string? reason = null, CancellationToken cancellation = default);

/// <summary>
/// Waits for an orchestration to start running and returns a <see cref="OrchestrationMetadata"/>
/// object that contains metadata about the started instance.
Expand Down
5 changes: 5 additions & 0 deletions src/Client/Core/OrchestrationRuntimeStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public enum OrchestrationRuntimeStatus
/// The orchestration was scheduled but hasn't started running.
/// </summary>
Pending,

/// <summary>
/// The orchestration is in a suspended state.
/// </summary>
Suspended,
}
3 changes: 1 addition & 2 deletions src/Client/Grpc/Client.Grpc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grpc.Core" Version="2.39.1" />
<PackageReference Include="Microsoft.DurableTask.Sidecar.Protobuf" Version="0.3.1" />
<PackageReference Include="Microsoft.DurableTask.Sidecar.Protobuf" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
</ItemGroup>
Expand Down
44 changes: 44 additions & 0 deletions src/Client/Grpc/GrpcDurableTaskClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,50 @@ await this.sidecarClient.TerminateInstanceAsync(new P.TerminateRequest
});
}

/// <inheritdoc/>
public override async Task SuspendInstanceAsync(
string instanceId, string? reason = null, CancellationToken cancellation = default)
{
P.SuspendRequest request = new()
{
InstanceId = instanceId,
Reason = reason,
};

try
{
await this.sidecarClient.SuspendInstanceAsync(
request, cancellationToken: cancellation);
}
catch (RpcException e) when (e.StatusCode == StatusCode.Cancelled)
{
throw new OperationCanceledException(
$"The {nameof(this.SuspendInstanceAsync)} operation was canceled.", e, cancellation);
}
}

/// <inheritdoc/>
public override async Task ResumeInstanceAsync(
string instanceId, string? reason = null, CancellationToken cancellation = default)
{
P.ResumeRequest request = new()
{
InstanceId = instanceId,
Reason = reason,
};

try
{
await this.sidecarClient.ResumeInstanceAsync(
request, cancellationToken: cancellation);
}
catch (RpcException e) when (e.StatusCode == StatusCode.Cancelled)
{
throw new OperationCanceledException(
$"The {nameof(this.ResumeInstanceAsync)} operation was canceled.", e, cancellation);
}
}

/// <inheritdoc/>
public override async Task<OrchestrationMetadata?> GetInstanceMetadataAsync(
string instanceId,
Expand Down
1 change: 1 addition & 0 deletions src/Client/Grpc/ProtoUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ internal static P.OrchestrationStatus ToGrpcStatus(this OrchestrationRuntimeStat
OrchestrationRuntimeStatus.Pending => P.OrchestrationStatus.Pending,
OrchestrationRuntimeStatus.Running => P.OrchestrationStatus.Running,
OrchestrationRuntimeStatus.Terminated => P.OrchestrationStatus.Terminated,
OrchestrationRuntimeStatus.Suspended => P.OrchestrationStatus.Suspended,
_ => throw new ArgumentOutOfRangeException(nameof(status), "Unexpected value"),
};
#pragma warning restore 0618 // Referencing Obsolete member.
Expand Down
6 changes: 6 additions & 0 deletions src/Shared/Grpc/ProtoUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ internal static HistoryEvent ConvertHistoryEvent(P.HistoryEvent proto)
case P.HistoryEvent.EventTypeOneofCase.ExecutionTerminated:
historyEvent = new ExecutionTerminatedEvent(proto.EventId, proto.ExecutionTerminated.Input);
break;
case P.HistoryEvent.EventTypeOneofCase.ExecutionSuspended:
historyEvent = new ExecutionSuspendedEvent(proto.EventId, proto.ExecutionSuspended.Input);
break;
case P.HistoryEvent.EventTypeOneofCase.ExecutionResumed:
historyEvent = new ExecutionResumedEvent(proto.EventId, proto.ExecutionResumed.Input);
break;
case P.HistoryEvent.EventTypeOneofCase.TaskScheduled:
historyEvent = new TaskScheduledEvent(
proto.EventId,
Expand Down
3 changes: 1 addition & 2 deletions src/Worker/Grpc/Worker.Grpc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grpc.Core" Version="2.39.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
<PackageReference Include="Microsoft.DurableTask.Sidecar.Protobuf" Version="0.3.1" />
<PackageReference Include="Microsoft.DurableTask.Sidecar.Protobuf" Version="1.0.0" />
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public override Task RaiseEventAsync(
throw new NotImplementedException();
}

public override Task ResumeInstanceAsync(string instanceId, string? reason = null, CancellationToken cancellation = default)
{
throw new NotImplementedException();
}

public override Task<string> ScheduleNewOrchestrationInstanceAsync(
TaskName orchestratorName,
object? input = null,
Expand All @@ -114,6 +119,11 @@ public override Task<string> ScheduleNewOrchestrationInstanceAsync(
throw new NotImplementedException();
}

public override Task SuspendInstanceAsync(string instanceId, string? reason = null, CancellationToken cancellation = default)
{
throw new NotImplementedException();
}

public override Task TerminateAsync(string instanceId, object? output)
{
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ public override Task RaiseEventAsync(
throw new NotImplementedException();
}

public override Task ResumeInstanceAsync(string instanceId, string? reason = null, CancellationToken cancellation = default)
{
throw new NotImplementedException();
}

public override Task<string> ScheduleNewOrchestrationInstanceAsync(
TaskName orchestratorName,
object? input = null,
Expand All @@ -145,6 +150,11 @@ public override Task<string> ScheduleNewOrchestrationInstanceAsync(
throw new NotImplementedException();
}

public override Task SuspendInstanceAsync(string instanceId, string? reason = null, CancellationToken cancellation = default)
{
throw new NotImplementedException();
}

public override Task TerminateAsync(string instanceId, object? output)
{
throw new NotImplementedException();
Expand Down