-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathPinnedWorkflowV2.workflow.cs
More file actions
45 lines (36 loc) · 1.49 KB
/
PinnedWorkflowV2.workflow.cs
File metadata and controls
45 lines (36 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using Microsoft.Extensions.Logging;
using Temporalio.Common;
using Temporalio.Workflows;
namespace TemporalioSamples.WorkerVersioning;
// PinnedWorkflowV2 has changes that would make it incompatible with v1, and aren't protected by
// a patch.
[Workflow("PinnedWorkflow", VersioningBehavior = VersioningBehavior.Pinned)]
public class PinnedWorkflowV2
{
private readonly Queue<string> signals = new();
[WorkflowRun]
public async Task<string> RunAsync()
{
Workflow.Logger.LogInformation("PinnedWorkflowV2 started");
// Here we call an activity where we didn't before, which is an incompatible change.
await Workflow.ExecuteActivityAsync(
(MyActivities act) => act.SomeActivity("PinnedWorkflowV2"),
new() { ScheduleToCloseTimeout = TimeSpan.FromMinutes(5) });
while (true)
{
await Workflow.WaitConditionAsync(() => signals.Count > 0);
var signal = signals.Dequeue();
if (signal == "conclude")
{
break;
}
}
// We've also changed the activity type here, another incompatible change
await Workflow.ExecuteActivityAsync(
(MyActivities act) => act.SomeIncompatibleActivity(new("PinnedWorkflowV2", "hi")),
new() { ScheduleToCloseTimeout = TimeSpan.FromMinutes(5) });
return "PinnedWorkflowV2 result";
}
[WorkflowSignal]
public async Task DoNextSignalAsync(string signal) => signals.Enqueue(signal);
}