-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathPinnedWorkflowV1.workflow.cs
More file actions
44 lines (36 loc) · 1.47 KB
/
PinnedWorkflowV1.workflow.cs
File metadata and controls
44 lines (36 loc) · 1.47 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
using Microsoft.Extensions.Logging;
using Temporalio.Common;
using Temporalio.Workflows;
namespace TemporalioSamples.WorkerVersioning;
// PinnedWorkflowV1 demonstrates a workflow that likely has a short lifetime, and we want to always
// stay pinned to the same version it began on.
//
// Note that generally you won't want or need to include a version number in your workflow name if
// you're using the worker versioning feature. This sample does it to illustrate changes to the
// same code over time - but really what we're demonstrating here is the evolution of what would
// have been one workflow definition.
[Workflow("PinnedWorkflow", VersioningBehavior = VersioningBehavior.Pinned)]
public class PinnedWorkflowV1
{
private readonly Queue<string> signals = new();
[WorkflowRun]
public async Task<string> RunAsync()
{
Workflow.Logger.LogInformation("PinnedWorkflowV1 started");
while (true)
{
await Workflow.WaitConditionAsync(() => signals.Count > 0);
var signal = signals.Dequeue();
if (signal == "conclude")
{
break;
}
}
await Workflow.ExecuteActivityAsync(
(MyActivities act) => act.SomeActivity("PinnedWorkflowV1"),
new() { ScheduleToCloseTimeout = TimeSpan.FromMinutes(5) });
return "PinnedWorkflowV1 result";
}
[WorkflowSignal]
public async Task DoNextSignalAsync(string signal) => signals.Enqueue(signal);
}