-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathProgram.cs
More file actions
44 lines (37 loc) · 1.56 KB
/
Program.cs
File metadata and controls
44 lines (37 loc) · 1.56 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.Client;
using Temporalio.Common.EnvConfig;
using Temporalio.Worker;
using TemporalioSamples.EagerWorkflowStart;
// Create a client to localhost on default namespace
var connectOptions = ClientEnvConfig.LoadClientConnectOptions();
connectOptions.TargetHost ??= "localhost:7233";
connectOptions.LoggerFactory = LoggerFactory.Create(builder =>
builder.
AddSimpleConsole(options => options.TimestampFormat = "[HH:mm:ss] ").
SetMinimumLevel(LogLevel.Information));
var client = await TemporalClient.ConnectAsync(connectOptions);
const string TaskQueue = "eager-wf-start-sample";
// Create an activity instance
var activities = new Activities();
// Run worker and start workflow in same process to demonstrate eager workflow start
Console.WriteLine("Running worker and starting workflow with eager start...");
using var worker = new TemporalWorker(
client,
new TemporalWorkerOptions(TaskQueue).
AddActivity(activities.Greeting).
AddWorkflow<EagerWorkflowStartWorkflow>());
await worker.ExecuteAsync(async () =>
{
// Start workflow with eager start enabled
var handle = await client.StartWorkflowAsync(
(EagerWorkflowStartWorkflow wf) => wf.RunAsync("Temporal"),
new(id: $"eager-workflow-{Guid.NewGuid()}", taskQueue: TaskQueue)
{
RequestEagerStart = true,
});
Console.WriteLine($"Started workflow {handle.Id}");
// Wait for result
var result = await handle.GetResultAsync();
Console.WriteLine($"Workflow result: {result}");
});