< 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: 55
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 CShells.Lifecycle;
 2using Elsa.Abstractions;
 3using Elsa.Shells.Api.Endpoints.Shells;
 4using Elsa.Workflows;
 5using JetBrains.Annotations;
 6using Microsoft.AspNetCore.Http;
 7using Microsoft.Extensions.Logging;
 8
 9namespace Elsa.Shells.Api.Endpoints.Shells.ReloadAll;
 10
 11[PublicAPI]
 612internal class ReloadAll(IShellRegistry shellRegistry, IApiSerializer apiSerializer, ILogger<ReloadAll> logger) : ElsaEn
 13{
 14    public override void Configure()
 15    {
 416        Post("/shells/reload");
 417        ConfigurePermissions("actions:shells:reload");
 418    }
 19
 20    public override async Task HandleAsync(CancellationToken cancellationToken)
 21    {
 22        // CShells 0.0.15: ReloadActiveAsync replaces the old ReloadAllShellsAsync. Per-shell failures are surfaced
 23        // in each ReloadResult.Error rather than thrown; aggregate any errors into a single 503 response.
 224        var results = await shellRegistry.ReloadActiveAsync(cancellationToken: cancellationToken);
 325        var errors = results.Where(r => r.Error is not null).ToList();
 26
 227        if (errors.Count > 0)
 28        {
 229            var summary = string.Join("; ", errors.Select(r => $"{r.Name}: {r.Error!.Message}"));
 130            logger.LogError("Failed to reload {Count} shell(s): {Summary}", errors.Count, summary);
 131            var failedResponse = new ShellReloadResponse
 132            {
 133                Status = ShellReloadStatus.Failed,
 134                Timestamp = DateTimeOffset.UtcNow,
 135                Message = summary
 136            };
 137            await SendResponseAsync(failedResponse, StatusCodes.Status503ServiceUnavailable, cancellationToken);
 138            return;
 39        }
 40
 141        var response = new ShellReloadResponse
 142        {
 143            Status = ShellReloadStatus.Completed,
 144            Timestamp = DateTimeOffset.UtcNow
 145        };
 146        await SendResponseAsync(response, StatusCodes.Status200OK, cancellationToken);
 247    }
 48
 49    private async Task SendResponseAsync(ShellReloadResponse response, int statusCode, CancellationToken cancellationTok
 50    {
 251        var serializerOptions = apiSerializer.GetOptions();
 252        HttpContext.Response.StatusCode = statusCode;
 253        await HttpContext.Response.WriteAsJsonAsync(response, serializerOptions, cancellationToken);
 254    }
 55}