-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
58 lines (45 loc) · 1.43 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
using System.Diagnostics.Metrics;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Temporalio.Client;
using Temporalio.Extensions.DiagnosticSource;
using Temporalio.Extensions.OpenTelemetry;
using Temporalio.Runtime;
var builder = WebApplication.CreateBuilder(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["ConnectionStrings:temporal"];
opts.Namespace = Constants.Namespace;
opts.Interceptors = [new TracingInterceptor()];
opts.Runtime = runtime;
});
var app = builder.Build();
app.MapDefaultEndpoints();
app.UseHttpsRedirection();
app.MapGet("/say-hello", async Task<Results<Ok<string>, BadRequest<string>>> (
HttpContext ctx,
[FromQuery] string? name,
[FromServices] ITemporalClient client) =>
{
if (name is null or { Length: > 1000 })
{
return TypedResults.BadRequest($"Pass a name using query param {nameof(name)}");
}
var result = await client.ExecuteWorkflowAsync<HelloWorkflow, string>(x => x.RunAsync(name),
new WorkflowOptions
{
Id = name,
TaskQueue = Constants.TaskQueueName
});
return TypedResults.Ok(result);
});
app.Run();