-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
63 lines (53 loc) · 1.62 KB
/
Program.cs
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
using System.Diagnostics.Metrics;
using Temporalio.Activities;
using Temporalio.Extensions.DiagnosticSource;
using Temporalio.Extensions.Hosting;
using Temporalio.Extensions.OpenTelemetry;
using Temporalio.Runtime;
using Temporalio.Workflows;
var builder = Host.CreateApplicationBuilder(args);
using var meter = new Meter("Temporal.Client");
var runtime = new TemporalRuntime(new()
{
Telemetry = new()
{
Metrics = new() { CustomMetricMeter = new CustomMetricMeter(meter) },
},
});
builder.AddServiceDefaults();
builder.Services
.AddTemporalClient(opts =>
{
opts.TargetHost = builder.Configuration.GetConnectionString("temporal");
opts.Namespace = Constants.Namespace;
opts.Interceptors = new[] { new TracingInterceptor() };
opts.Runtime = runtime;
})
.AddHostedTemporalWorker(Constants.TaskQueueName)
.AddScopedActivities<HelloActivities>()
.AddWorkflow<HelloWorkflow>();
var host = builder.Build();
host.Run();
public static class Constants
{
public const string TaskQueueName = "aspire-worker-task-queue";
public const string Namespace = "test1";
}
[Workflow]
public class HelloWorkflow
{
[WorkflowRun]
public async Task<string> RunAsync(string name)
{
return await Workflow.ExecuteActivityAsync((HelloActivities act) => act.SayHello(name),
new() { ScheduleToCloseTimeout = TimeSpan.FromMinutes(5) });
}
}
public class HelloActivities
{
[Activity]
public Task<string> SayHello(string name)
{
return Task.FromResult("Hello " + name);
}
}