< Summary

Information
Class: Elsa.Shells.Api.Endpoints.Shells.ReloadAll.ReloadAll
Assembly: Elsa.Shells.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Shells.Api/Endpoints/Shells/ReloadAll/Endpoint.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 56
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Configure()100%11100%
HandleAsync()100%22100%
SendResponseAsync()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Shells.Api/Endpoints/Shells/ReloadAll/Endpoint.cs

#LineLine coverage
 1using Elsa.Authorization;
 2using CShells.Lifecycle;
 3using Elsa.Abstractions;
 4using Elsa.Shells.Api.Endpoints.Shells;
 5using Elsa.Workflows;
 6using JetBrains.Annotations;
 7using Microsoft.AspNetCore.Http;
 8using Microsoft.Extensions.Logging;
 9
 10namespace Elsa.Shells.Api.Endpoints.Shells.ReloadAll;
 11
 12[PublicAPI]
 813internal class ReloadAll(IShellRegistry shellRegistry, IApiSerializer apiSerializer, ILogger<ReloadAll> logger) : ElsaEn
 14{
 15    public override void Configure()
 16    {
 617        Post("/shells/reload");
 618        RequirePermission(Elsa.Shells.Api.Permissions.ShellPermissions.Shells, "reload");
 619    }
 20
 21    public override async Task HandleAsync(CancellationToken cancellationToken)
 22    {
 23        // CShells 0.0.15: ReloadActiveAsync replaces the old ReloadAllShellsAsync. Per-shell failures are surfaced
 24        // in each ReloadResult.Error rather than thrown; aggregate any errors into a single 503 response.
 225        var results = await shellRegistry.ReloadActiveAsync(cancellationToken: cancellationToken);
 326        var errors = results.Where(r => r.Error is not null).ToList();
 27
 228        if (errors.Count > 0)
 29        {
 230            var summary = string.Join("; ", errors.Select(r => $"{r.Name}: {r.Error!.Message}"));
 131            logger.LogError("Failed to reload {Count} shell(s): {Summary}", errors.Count, summary);
 132            var failedResponse = new ShellReloadResponse
 133            {
 134                Status = ShellReloadStatus.Failed,
 135                Timestamp = DateTimeOffset.UtcNow,
 136                Message = summary
 137            };
 138            await SendResponseAsync(failedResponse, StatusCodes.Status503ServiceUnavailable, cancellationToken);
 139            return;
 40        }
 41
 142        var response = new ShellReloadResponse
 143        {
 144            Status = ShellReloadStatus.Completed,
 145            Timestamp = DateTimeOffset.UtcNow
 146        };
 147        await SendResponseAsync(response, StatusCodes.Status200OK, cancellationToken);
 248    }
 49
 50    private async Task SendResponseAsync(ShellReloadResponse response, int statusCode, CancellationToken cancellationTok
 51    {
 252        var serializerOptions = apiSerializer.GetOptions();
 253        HttpContext.Response.StatusCode = statusCode;
 254        await HttpContext.Response.WriteAsJsonAsync(response, serializerOptions, cancellationToken);
 255    }
 56}