Skip to content

Commit b736268

Browse files
committed
feat: add ILongRunningCgScriptApiClient
1 parent 3fa5825 commit b736268

File tree

9 files changed

+39
-18
lines changed

9 files changed

+39
-18
lines changed

Catglobe.CgScript.Common/Catglobe.CgScript.Common.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
<ItemGroup>
3939
<PackageReference Include="OpenTelemetry.Api" Version="1.12.0" />
40+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.8" />
41+
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.7.0" />
4042
</ItemGroup>
4143

4244
<PropertyGroup>

Catglobe.CgScript.Deployment/Catglobe.CgScript.Deployment.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
</ItemGroup>
4141

4242
<ItemGroup>
43-
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.3" />
44-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.3" />
45-
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.3" />
46-
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.3" />
47-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.3" />
48-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.3" />
43+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.8" />
44+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.8" />
45+
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.8" />
46+
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.8" />
47+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.8" />
48+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.8" />
4949
</ItemGroup>
5050

5151
</Project>

Catglobe.CgScript.Deployment/HostExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.Extensions.DependencyInjection.Extensions;
66
using Microsoft.Extensions.Options;
77
using OpenTelemetry.Trace;
8+
using Polly;
89

910
namespace Catglobe.CgScript.Deployment;
1011

@@ -44,7 +45,11 @@ private static IServiceCollection AddCommonCgScript(IServiceCollection services)
4445
var site = sp.GetRequiredService<IOptions<DeploymentOptions>>().Value.Authority;
4546
httpClient.BaseAddress = new(site + "api/CgScriptDeployment/");
4647
})
47-
.AddHttpMessageHandler<DeploymentAuthHandler>();
48+
.AddHttpMessageHandler<DeploymentAuthHandler>()
49+
.AddStandardResilienceHandler(o => {
50+
o.AttemptTimeout.Timeout = TimeSpan.FromMinutes(10);
51+
o.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(20);
52+
});
4853
services.AddHttpClient<DeploymentAuthenticator>((sp, httpClient) => {
4954
httpClient.BaseAddress = sp.GetRequiredService<IOptions<DeploymentOptions>>().Value.Authority;
5055
});

Catglobe.CgScript.Runtime/ApiClientBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Catglobe.CgScript.Runtime;
1010

11-
internal abstract class ApiClientBase(HttpClient httpClient, ILogger<ICgScriptApiClient> logger) : ICgScriptApiClient
11+
internal abstract class ApiClientBase(HttpClient httpClient, ILogger<ICgScriptApiClient> logger) : ICgScriptApiClient, ILongRunningCgScriptApiClient
1212
{
1313
public async Task<ScriptResult<TR>> Execute<TP, TR>(string scriptName, TP parameter, JsonTypeInfo<TP> callJsonTypeInfo, JsonTypeInfo<TR> resultJsonTypeInfo, CancellationToken cancellationToken)
1414
{

Catglobe.CgScript.Runtime/Catglobe.CgScript.Runtime.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<ItemGroup>
3232
<FrameworkReference Include="Microsoft.AspNetCore.App" />
33-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.3" />
33+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.8" />
3434
</ItemGroup>
3535

3636
<ItemGroup>

Catglobe.CgScript.Runtime/HostExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ private static IServiceCollection AddCommonCgScript(IServiceCollection services,
4646
? services.AddHttpClient<ICgScriptApiClient, DevelopmentModeCgScriptApiClient>(configureClient)
4747
: services.AddHttpClient<ICgScriptApiClient, CgScriptApiClient>(configureClient))
4848
.AddHttpMessageHandler<CgScriptAuthHandler>();
49+
50+
(isDevelopment
51+
? services.AddHttpClient<ILongRunningCgScriptApiClient, DevelopmentModeCgScriptApiClient>(configureClient)
52+
: services.AddHttpClient<ILongRunningCgScriptApiClient, CgScriptApiClient>(configureClient))
53+
.AddHttpMessageHandler<CgScriptAuthHandler>()
54+
.AddStandardResilienceHandler(o => {
55+
o.AttemptTimeout.Timeout = TimeSpan.FromMinutes(30);
56+
o.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(60);
57+
});
4958
return services;
5059
}
5160
}

Catglobe.CgScript.Runtime/ICgScriptApiClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,8 @@ public interface ICgScriptApiClient
9696
public Task<ScriptResult<TR>> Execute<TR>(string scriptName, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default);
9797

9898
}
99+
100+
/// <summary>
101+
/// Long-running script API client. Configured for 30 minutes timeout vs the default 10 sec.
102+
/// </summary>
103+
public interface ILongRunningCgScriptApiClient : ICgScriptApiClient;

demos/BlazorWebApp/BlazorWebApp.Client/BlazorWebApp.Client.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.3" />
13-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="9.0.3" />
12+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.8" />
13+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="9.0.8" />
1414
</ItemGroup>
1515

1616
</Project>

demos/BlazorWebApp/BlazorWebApp/BlazorWebApp.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
<ProjectReference Include="..\..\..\Catglobe.CgScript.Deployment\Catglobe.CgScript.Deployment.csproj" />
1212
<ProjectReference Include="..\..\..\Catglobe.CgScript.Runtime\Catglobe.CgScript.Runtime.csproj" />
1313
<ProjectReference Include="..\BlazorWebApp.Client\BlazorWebApp.Client.csproj" />
14-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.3" />
15-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="9.0.3" />
16-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.3" />
17-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.3" />
18-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.3">
14+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.8" />
15+
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="9.0.8" />
16+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.8" />
17+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.8" />
18+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.8">
1919
<PrivateAssets>all</PrivateAssets>
2020
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2121
</PackageReference>
22-
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.3" />
23-
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery.Yarp" Version="9.1.0" />
22+
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.8" />
23+
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery.Yarp" Version="9.4.1" />
2424
</ItemGroup>
2525

2626
<!--Added for this demo-->

0 commit comments

Comments
 (0)