Skip to content
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
17 changes: 17 additions & 0 deletions src/Shawarma.Aspire.Hosting/KnownShawarmaCommands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Shawarma.Aspire.Hosting;

/// <summary>
/// Known Aspire command names for Shawarma Aspire services.
/// </summary>
public static class KnownShawarmaCommands
{
/// <summary>
/// The command name for enabling Shawarma services.
/// </summary>
public const string EnableShawarma = "enable-shawarma";

/// <summary>
/// The command name for disabling Shawarma services.
/// </summary>
public const string DisableShawarma = "disable-shawarma";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ namespace Shawarma.Aspire.Hosting;
/// </summary>
public static class ShawarmaResourceBuilderExtensions
{
private const string EnableShawarmaCommandName = "enableShawarma";
private const string DisableShawarmaCommandName = "disableShawarma";

private static readonly string[] s_httpSchemes = ["https", "http"];

private static Func<EndpointReference> NamedEndpointSelector<TResource>(IResourceBuilder<TResource> builder, string endpointName)
Expand Down Expand Up @@ -141,7 +138,7 @@ await notificationService.PublishUpdateAsync(builder.Resource,
path: options.ApplicationStatePath,
displayName: "Start Shawarma Services",
endpointSelector: endpointSelector,
commandName: EnableShawarmaCommandName,
commandName: KnownShawarmaCommands.EnableShawarma,
commandOptions: new HttpCommandOptions
{
Method = HttpMethod.Post,
Expand Down Expand Up @@ -179,7 +176,7 @@ await notificationService.PublishUpdateAsync(builder.Resource,
path: options.ApplicationStatePath,
displayName: "Stop Shawarma Services",
endpointSelector: endpointSelector,
commandName: DisableShawarmaCommandName,
commandName: KnownShawarmaCommands.DisableShawarma,
commandOptions: new HttpCommandOptions
{
Method = HttpMethod.Post,
Expand Down Expand Up @@ -224,7 +221,7 @@ await notificationService.PublishUpdateAsync(resource,
{
var commandService = e.Services.GetRequiredService<ResourceCommandService>();

var result = await commandService.ExecuteCommandAsync(resource, EnableShawarmaCommandName, cancellationToken);
var result = await commandService.ExecuteCommandAsync(resource, KnownShawarmaCommands.EnableShawarma, cancellationToken);
if (result is { Success: false, Canceled: false })
{
throw new InvalidOperationException($"Failed to enable Shawarma services on startup: {result.ErrorMessage}");
Expand Down
Loading