| | | 1 | | using CShells.Management; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Shells.Api.Endpoints.Shells; |
| | | 4 | | using Elsa.Workflows; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | using Microsoft.AspNetCore.Http; |
| | | 7 | | using Microsoft.Extensions.Logging; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Shells.Api.Endpoints.Shells.ReloadAll; |
| | | 10 | | |
| | | 11 | | [PublicAPI] |
| | 6 | 12 | | internal class ReloadAll(IShellManager shellManager, IApiSerializer apiSerializer, ILogger<ReloadAll> logger) : ElsaEndp |
| | | 13 | | { |
| | | 14 | | public override void Configure() |
| | | 15 | | { |
| | 4 | 16 | | Post("/shells/reload"); |
| | 4 | 17 | | ConfigurePermissions("actions:shells:reload"); |
| | 4 | 18 | | } |
| | | 19 | | |
| | | 20 | | public override async Task HandleAsync(CancellationToken cancellationToken) |
| | | 21 | | { |
| | | 22 | | try |
| | | 23 | | { |
| | 2 | 24 | | await shellManager.ReloadAllShellsAsync(cancellationToken); |
| | 1 | 25 | | } |
| | 1 | 26 | | catch (InvalidOperationException ex) |
| | | 27 | | { |
| | 1 | 28 | | logger.LogError(ex, "Failed to reload all shells"); |
| | 1 | 29 | | var failedResponse = new ShellReloadResponse |
| | 1 | 30 | | { |
| | 1 | 31 | | Status = ShellReloadStatus.Failed, |
| | 1 | 32 | | Timestamp = DateTimeOffset.UtcNow, |
| | 1 | 33 | | Message = ex.Message |
| | 1 | 34 | | }; |
| | 1 | 35 | | await SendResponseAsync(failedResponse, StatusCodes.Status503ServiceUnavailable, cancellationToken); |
| | 1 | 36 | | return; |
| | | 37 | | } |
| | | 38 | | |
| | 1 | 39 | | var response = new ShellReloadResponse |
| | 1 | 40 | | { |
| | 1 | 41 | | Status = ShellReloadStatus.Completed, |
| | 1 | 42 | | Timestamp = DateTimeOffset.UtcNow |
| | 1 | 43 | | }; |
| | 1 | 44 | | await SendResponseAsync(response, StatusCodes.Status200OK, cancellationToken); |
| | 2 | 45 | | } |
| | | 46 | | |
| | | 47 | | private async Task SendResponseAsync(ShellReloadResponse response, int statusCode, CancellationToken cancellationTok |
| | | 48 | | { |
| | 2 | 49 | | var serializerOptions = apiSerializer.GetOptions(); |
| | 2 | 50 | | HttpContext.Response.StatusCode = statusCode; |
| | 2 | 51 | | await HttpContext.Response.WriteAsJsonAsync(response, serializerOptions, cancellationToken); |
| | 2 | 52 | | } |
| | | 53 | | } |