Skip to content
This repository was archived by the owner on Aug 4, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected async Task<IAOSClient> GetScaleUnitAosClient()
if (scaleUnitAosClient is null)
{
ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId());
SetScaleUnitAosClient(await AOSClient.Construct(scaleUnit));
await ReliableRun.Execute(async () => SetScaleUnitAosClient(await AOSClient.Construct(scaleUnit)), "Connecting to AOS");
Comment thread
Antonstockmarr marked this conversation as resolved.
}
return scaleUnitAosClient;
}
Expand All @@ -30,7 +30,7 @@ protected async Task<IAOSClient> GetHubAosClient()
if (hubAosClient is null)
{
ScaleUnitInstance hub = Config.HubScaleUnit();
SetHubAosClient(await AOSClient.Construct(hub));
await ReliableRun.Execute(async () => SetHubAosClient(await AOSClient.Construct(hub)), "Connecting to AOS");
}
return hubAosClient;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,19 @@ public static async Task<AOSClient> Construct(ScaleUnitInstance scaleUnitInstanc
httpClient.Timeout = TimeSpan.FromMinutes(20);
httpClient.DefaultRequestHeaders.Add("Authorization", await OAuthHelper.GetAuthenticationHeader(aadTenant, aadClientAppId, aadClientAppSecret, aadResource));

return new AOSClient(httpClient, scaleUnitInstance.AOSRequestPathPrefix());
var aosClient = new AOSClient(httpClient, scaleUnitInstance.AOSRequestPathPrefix());

await aosClient.Ping();

return aosClient;
}

private async Task Ping()
{
string path = $"{requestPathPrefix}ping/";
string getPayload = "{}";

_ = await SendRequest(path, getPayload);
}

public async Task<ScaleUnitEnvironmentConfiguration> WriteScaleUnitConfiguration(ScaleUnitEnvironmentConfiguration config)
Expand Down Expand Up @@ -183,7 +195,16 @@ private async Task<string> SendRequest(string path, string payload)
Content = new StringContent(payload, Encoding.UTF8, "application/json")
};

HttpResponseMessage response = await httpClient.SendAsync(msg);
HttpResponseMessage response;
try
{
response = await httpClient.SendAsync(msg);
}
catch (TaskCanceledException)
{
throw new Exception("The server did not respond before timeout");
}

string result = await response.Content.ReadAsStringAsync();

if (response.IsSuccessStatusCode)
Expand Down