From 3910c9d844e1e601b283405f3e6d6fb8ef0afe73 Mon Sep 17 00:00:00 2001 From: Elan Hasson <234704+ElanHasson@users.noreply.github.com> Date: Tue, 16 Apr 2024 19:17:00 -0400 Subject: [PATCH] Updated syntax, package version, and error handling in Temporal Server (#46) * Updated the syntax for adding an interceptor in `Program.cs` and for retrieving the "temporal" connection string. * Swapped the order of `port` and `targetPort` parameters in `TemporalServerContainerBuilderExtensions.cs` for improved readability. * Changed the behavior in `TemporalServerExecutableResource.cs` and `TemporalServerContainerResource.cs` to return `null` instead of throwing an exception when no endpoints are allocated. * Upgraded `InfinityFlow.Aspire.Temporal` package version from `0.4.3` to `0.5.1`. --- sample/Api/Program.cs | 2 +- sample/Worker/Program.cs | 2 +- .../InfinityFlow.Aspire.Temporal.csproj | 2 +- .../TemporalServerContainerBuilderExtensions.cs | 8 ++++---- .../TemporalServerExecutableResource.cs | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sample/Api/Program.cs b/sample/Api/Program.cs index f9cf0c9..040d182 100644 --- a/sample/Api/Program.cs +++ b/sample/Api/Program.cs @@ -26,7 +26,7 @@ { opts.TargetHost = builder.Configuration["ConnectionStrings:temporal"]; opts.Namespace = Constants.Namespace; - opts.Interceptors = new[] { new TracingInterceptor() }; + opts.Interceptors = [new TracingInterceptor()]; opts.Runtime = runtime; }); diff --git a/sample/Worker/Program.cs b/sample/Worker/Program.cs index 22ba603..beeb5a0 100644 --- a/sample/Worker/Program.cs +++ b/sample/Worker/Program.cs @@ -24,7 +24,7 @@ builder.Services .AddTemporalClient(opts => { - opts.TargetHost = builder.Configuration["ConnectionStrings:temporal"]; + opts.TargetHost = builder.Configuration.GetConnectionString("temporal"); opts.Namespace = Constants.Namespace; opts.Interceptors = new[] { new TracingInterceptor() }; opts.Runtime = runtime; diff --git a/src/InfinityFlow.Aspire.Temporal/InfinityFlow.Aspire.Temporal.csproj b/src/InfinityFlow.Aspire.Temporal/InfinityFlow.Aspire.Temporal.csproj index 5a25d3b..57fa92d 100644 --- a/src/InfinityFlow.Aspire.Temporal/InfinityFlow.Aspire.Temporal.csproj +++ b/src/InfinityFlow.Aspire.Temporal/InfinityFlow.Aspire.Temporal.csproj @@ -7,7 +7,7 @@ true true InfinityFlow.Aspire.Temporal - 0.5.0 + 0.5.1 true README.md LICENSE diff --git a/src/InfinityFlow.Aspire.Temporal/TemporalServerContainerBuilderExtensions.cs b/src/InfinityFlow.Aspire.Temporal/TemporalServerContainerBuilderExtensions.cs index 47a1431..60bd61e 100644 --- a/src/InfinityFlow.Aspire.Temporal/TemporalServerContainerBuilderExtensions.cs +++ b/src/InfinityFlow.Aspire.Temporal/TemporalServerContainerBuilderExtensions.cs @@ -78,21 +78,21 @@ private static async Task> Add var resourceBuilder = builder.AddResource(container) .WithAnnotation(new ContainerImageAnnotation() { Image = "aspire-temporal-server-helper", Tag = "latest" }) .WithArgs(args.GetArgs()) - .WithHttpsEndpoint(name: "server", targetPort: args.Port, port: 7233).AsHttp2Service(); // Internal port is always 7233 + .WithHttpsEndpoint(name: "server", port: args.Port, targetPort: 7233).AsHttp2Service(); // Internal port is always 7233 if (args.Headless is not true) { - resourceBuilder.WithHttpEndpoint(name: "ui", targetPort: args.UiPort, port: 8233); // Internal port is always 8233 + resourceBuilder.WithHttpEndpoint(name: "ui", port: args.UiPort, targetPort: 8233); // Internal port is always 8233 } if (args.MetricsPort is not null) { - resourceBuilder.WithHttpEndpoint(name: "metrics", targetPort: args.MetricsPort, port: 7235); // Internal port is always 7235 + resourceBuilder.WithHttpEndpoint(name: "metrics", port: args.MetricsPort, targetPort: 7235); // Internal port is always 7235 } if (args.HttpPort is not null) { - resourceBuilder.WithHttpEndpoint(name: "http", targetPort: args.HttpPort, port: 7234); // Internal port is always 7234 + resourceBuilder.WithHttpEndpoint(name: "http", port: args.HttpPort, targetPort: 7234); // Internal port is always 7234 } return resourceBuilder; diff --git a/src/InfinityFlow.Aspire.Temporal/TemporalServerExecutableResource.cs b/src/InfinityFlow.Aspire.Temporal/TemporalServerExecutableResource.cs index a4d0038..607b320 100644 --- a/src/InfinityFlow.Aspire.Temporal/TemporalServerExecutableResource.cs +++ b/src/InfinityFlow.Aspire.Temporal/TemporalServerExecutableResource.cs @@ -13,7 +13,7 @@ public class TemporalServerExecutableResource(string name, TemporalServerResourc var endpoints = this.GetEndpoints().Where(e => e.IsAllocated).ToList(); if (endpoints.Count==0) { - throw new DistributedApplicationException("Expected allocated endpoints!"); + return null; } var server = endpoints.SingleOrDefault(x => x.EndpointName == "server"); @@ -33,7 +33,7 @@ public class TemporalServerContainerResource(string name, TemporalServerResource var endpoints = this.GetEndpoints().Where(e => e.IsAllocated).ToList(); if (endpoints.Count == 0) { - throw new DistributedApplicationException("Expected allocated endpoints!"); + return null; } var server = endpoints.SingleOrDefault(x => x.EndpointName == "server");