-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathProgram.cs
More file actions
73 lines (57 loc) · 2.62 KB
/
Program.cs
File metadata and controls
73 lines (57 loc) · 2.62 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
namespace TemporalioSamples.CounterInterceptor;
using Temporalio.Client;
using Temporalio.Common.EnvConfig;
using Temporalio.Worker;
internal class Program
{
private static async Task Main(string[] args)
{
var counterInterceptor = new MyCounterInterceptor();
var connectOptions = ClientEnvConfig.LoadClientConnectOptions();
connectOptions.TargetHost ??= "localhost:7233";
connectOptions.Interceptors = new[]
{
counterInterceptor,
};
var client = await TemporalClient.ConnectAsync(connectOptions);
var activities = new MyActivities();
var taskQueue = "CounterInterceptorTaskQueue";
var workerOptions = new TemporalWorkerOptions(taskQueue).
AddAllActivities(activities).
AddWorkflow<MyWorkflow>().
AddWorkflow<MyChildWorkflow>();
// workerOptions.Interceptors = new[] { counterInterceptor };
using var worker = new TemporalWorker(
client,
workerOptions);
// Run worker until cancelled
Console.WriteLine("Running worker...");
// Start the workers
await worker.ExecuteAsync(async () =>
{
// Start the workflow
var handle = await client.StartWorkflowAsync(
(MyWorkflow wf) => wf.RunAsync(),
new(id: Guid.NewGuid().ToString(), taskQueue: taskQueue));
Console.WriteLine("Sending name and title to workflow");
await handle.SignalAsync(wf => wf.SignalNameAndTitleAsync("John", "Customer"));
var name = await handle.QueryAsync(wf => wf.Name);
var title = await handle.QueryAsync(wf => wf.Title);
// Send exit signal to workflow
await handle.SignalAsync(wf => wf.ExitAsync());
var result = await handle.GetResultAsync();
Console.WriteLine($"Workflow result is {result}");
Console.WriteLine("Query results: ");
Console.WriteLine($"\tName: {name}");
Console.WriteLine($"\tTitle: {title}");
// Print worker counter info
Console.WriteLine("\nCollected Worker Counter Info:\n");
Console.WriteLine(counterInterceptor.WorkerInfo());
Console.WriteLine($"Number of unique workflows: {counterInterceptor.Counts.Count}");
// Print client counter info
Console.WriteLine();
Console.WriteLine("Collected Client Counter Info:\n");
Console.WriteLine(counterInterceptor.ClientInfo());
});
}
}