Skip to content

Commit

Permalink
Fix URLs and ping errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dluc committed Nov 23, 2024
1 parent 90ca96b commit a6252ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 0 additions & 4 deletions aspire-orchestrator/Aspire.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
.WithReference(workbenchServiceEndpoint)
.WaitFor(workbenchService);

// Console.WriteLine($"{dotnetAgent.GetEndpoint("http")}");
// Console.WriteLine(dotnetAgent.GetEndpoint("http").Url);
// Environment.Exit(0);

// The agent needs to reference its own endpoint, in order to send it to the workbench service when during the registration
dotnetAgent
.WithEnvironment("Workbench__ConnectorEndpoint", $"{dotnetAgent.GetEndpoint("http")}/myagents")
Expand Down
15 changes: 12 additions & 3 deletions libraries/dotnet/WorkbenchConnector/WorkbenchConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public virtual async Task ConnectAsync(CancellationToken cancellationToken = def
this.Log.LogInformation("Connecting {1} {2} {3} to {4}...",
this.WorkbenchConfig.ConnectorName, this.WorkbenchConfig.ConnectorId, this.WorkbenchConfig.ConnectorEndpoint, this.WorkbenchConfig.WorkbenchEndpoint);
#pragma warning disable CS4014 // ping runs in the background without blocking
this._pingTimer ??= new Timer(_ => this.PingSemanticWorkbenchBackendAsync(cancellationToken), null, 0, 10000);
this._pingTimer ??= new Timer(_ => this.PingSemanticWorkbenchBackendAsync(cancellationToken), null, 0, PingFrequencyMS);
#pragma warning restore CS4014

List<AgentInfo> agents = await this.Storage.GetAllAgentsAsync(cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -373,9 +373,12 @@ public virtual async Task DeleteFileAsync(

public virtual async Task PingSemanticWorkbenchBackendAsync(CancellationToken cancellationToken)
{
this.Log.LogTrace("Pinging workbench backend");
// Disable timer during the request
this._pingTimer?.Change(Timeout.Infinite, Timeout.Infinite);

string path = Constants.AgentServiceRegistration.Path
.Replace(Constants.AgentServiceRegistration.Placeholder, this.WorkbenchConfig.ConnectorId, StringComparison.OrdinalIgnoreCase);
this.Log.LogTrace("Pinging workbench backend at {Path}", path);

var data = new
{
Expand All @@ -386,10 +389,15 @@ public virtual async Task PingSemanticWorkbenchBackendAsync(CancellationToken ca
};

await this.SendAsync(HttpMethod.Put, path, data, null, "PingSWBackend", cancellationToken).ConfigureAwait(false);

// Activate timer
this._pingTimer?.Change(TimeSpan.FromMilliseconds(PingFrequencyMS), TimeSpan.FromMilliseconds(PingFrequencyMS));
}

#region internals ===========================================================================

private const int PingFrequencyMS = 10000;

public void Dispose()
{
this.Dispose(true);
Expand All @@ -414,11 +422,12 @@ protected virtual async Task<HttpResponseMessage> SendAsync(
string description,
CancellationToken cancellationToken)
{
url = url.TrimStart('/');
try
{
this.Log.LogTrace("Preparing request: {2}", description);
HttpRequestMessage request = this.PrepareRequest(method, url, data, agentId);
this.Log.LogTrace("Sending request {0} {1} [{2}]", method, url.HtmlEncode(), description);
this.Log.LogTrace("Sending request {Method} {BaseAddress}{Path} [{Description}]", method, this.HttpClient.BaseAddress, url.HtmlEncode(), description);
HttpResponseMessage result = await this.HttpClient
.SendAsync(request, cancellationToken)
.ConfigureAwait(false);
Expand Down

0 comments on commit a6252ad

Please sign in to comment.