quickstarts/tutorials/workflow/csharp/challenges-tips/VersioningWorkflow.cs

50 lines
1.8 KiB
C#

using Dapr.Workflow;
namespace WorkflowApp;
/// <summary>
/// This is the initial version of the workflow.
/// Note that the input argument for both activities is the orderItem (string).
/// </summary>
internal sealed class VersioningWorkflow1 : Workflow<string, int>
{
public override async Task<int> RunAsync(WorkflowContext context, string orderItem)
{
var resultA = await context.CallActivityAsync<int>(
"ActivityA",
orderItem);
var resultB = await context.CallActivityAsync<int>(
"ActivityB",
orderItem);
return resultA + resultB;
}
}
/// <summary>
/// This is the updated version of the workflow.
/// The input for ActivityB has changed from orderItem (string) to resultA (int).
/// If there are in-flight workflow instances that were started with the previous version
/// of this workflow, these will fail when the new version of the workflow is deployed
/// and the workflow name remains the same, since the runtime parameters do not match with the persisted state.
/// It is recommended to version workflows by creating a new workflow class with a new name:
/// {workflowname}1 -> {workflowname}2
/// Try to avoid making breaking changes in perpetual workflows (that use the `ContinueAsNew` method)
/// since these are difficult to replace with a new version.
/// </summary>
internal sealed class VersioningWorkflow2 : Workflow<string, int>
{
public override async Task<int> RunAsync(WorkflowContext context, string orderItem)
{
var resultA = await context.CallActivityAsync<int>(
"ActivityA",
orderItem);
var resultB = await context.CallActivityAsync<int>(
"ActivityB",
resultA);
return resultA + resultB;
}
}