Skip to content

Commit

Permalink
Allows configuring the engine manager
Browse files Browse the repository at this point in the history
  • Loading branch information
daveaglick committed Jun 8, 2023
1 parent 1de2117 commit 9c99d05
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.0-beta.69

- Added a configurator for the `IEngineManager` and a corresponding bootstrapper `ConfigureEngineManager()` extension method to allow customizing the engine manager used in most commands just prior to it executing the engine (useful for last-minute pipeline customization and some other niche use cases).

# 1.0.0-beta.68

- Improved the `HttpClient.SendWithRetryAsync()` extension to log retries at the information level since they may indicate other problems, and to retry during internal `HttpClient` timeouts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,17 @@ public static Bootstrapper AddConfigurator<TConfigurable>(
bootstrapper.Configurators.Add(configurator);
return bootstrapper;
}

public static TBootstrapper ConfigureEngineManager<TBootstrapper>(
this TBootstrapper bootstrapper, Action<IEngineManager> action)
where TBootstrapper : IBootstrapper
{
bootstrapper.ThrowIfNull(nameof(bootstrapper));
action.ThrowIfNull(nameof(action));
bootstrapper.Configurators.Add(action);
return bootstrapper;
}

// Most of the Configure...() methods are in Statiq.Common if they configure a common interface
}
}
9 changes: 9 additions & 0 deletions src/core/Statiq.App/Commands/EngineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public EngineManager(
IServiceCollection serviceCollection,
Bootstrapper bootstrapper)
{
Bootstrapper = bootstrapper;

// Get the standard input stream
string input = null;
if (commandSettings?.StdIn == true)
Expand Down Expand Up @@ -78,6 +80,8 @@ public EngineManager(
_logger.LogInformation($"Cache path:{Environment.NewLine} {Engine.FileSystem.CachePath}");
}

public IBootstrapper Bootstrapper { get; set; }

public Engine Engine { get; }

public string[] Pipelines { get; set; }
Expand All @@ -86,6 +90,11 @@ public EngineManager(

public async Task<ExitCode> ExecuteAsync(CancellationTokenSource cancellationTokenSource)
{
// Provide a chance to configure the engine manager, which is mainly useful for tweaking
// the pipelines and/or engine right before executing
Bootstrapper.Configurators.Configure<IEngineManager>(this);

// Execute the engine and log all errors (including cancellation requests)
try
{
await Engine.ExecuteAsync(Pipelines, NormalPipelines, cancellationTokenSource?.Token ?? CancellationToken.None);
Expand Down
5 changes: 3 additions & 2 deletions src/core/Statiq.App/Commands/IEngineManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Threading;
using System.Threading.Tasks;
using Statiq.Common;
using Statiq.Core;

namespace Statiq.App
{
public interface IEngineManager
public interface IEngineManager : IConfigurable
{
Engine Engine { get; }

Expand All @@ -14,4 +15,4 @@ public interface IEngineManager

Task<ExitCode> ExecuteAsync(CancellationTokenSource cancellationTokenSource);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace Statiq.Common
{
public static class BootstrapperConfigurationExtensions
{
public static TBootstrapper BuildConfiguration<TBootstrapper>(this TBootstrapper bootstrapper, Action<IConfigurationBuilder> action)
public static TBootstrapper BuildConfiguration<TBootstrapper>(
this TBootstrapper bootstrapper, Action<IConfigurationBuilder> action)
where TBootstrapper : IBootstrapper
{
bootstrapper.ThrowIfNull(nameof(bootstrapper));
Expand All @@ -15,7 +16,8 @@ public static TBootstrapper BuildConfiguration<TBootstrapper>(this TBootstrapper
return bootstrapper;
}

public static TBootstrapper ConfigureServices<TBootstrapper>(this TBootstrapper bootstrapper, Action<IServiceCollection> action)
public static TBootstrapper ConfigureServices<TBootstrapper>(
this TBootstrapper bootstrapper, Action<IServiceCollection> action)
where TBootstrapper : IBootstrapper
{
bootstrapper.ThrowIfNull(nameof(bootstrapper));
Expand All @@ -24,7 +26,8 @@ public static TBootstrapper ConfigureServices<TBootstrapper>(this TBootstrapper
return bootstrapper;
}

public static TBootstrapper ConfigureServices<TBootstrapper>(this TBootstrapper bootstrapper, Action<IServiceCollection, IReadOnlySettings> action)
public static TBootstrapper ConfigureServices<TBootstrapper>(
this TBootstrapper bootstrapper, Action<IServiceCollection, IReadOnlySettings> action)
where TBootstrapper : IBootstrapper
{
bootstrapper.ThrowIfNull(nameof(bootstrapper));
Expand All @@ -33,7 +36,8 @@ public static TBootstrapper ConfigureServices<TBootstrapper>(this TBootstrapper
return bootstrapper;
}

public static TBootstrapper ConfigureServices<TBootstrapper>(this TBootstrapper bootstrapper, Action<IServiceCollection, IReadOnlySettings, IReadOnlyFileSystem> action)
public static TBootstrapper ConfigureServices<TBootstrapper>(
this TBootstrapper bootstrapper, Action<IServiceCollection, IReadOnlySettings, IReadOnlyFileSystem> action)
where TBootstrapper : IBootstrapper
{
bootstrapper.ThrowIfNull(nameof(bootstrapper));
Expand All @@ -42,12 +46,13 @@ public static TBootstrapper ConfigureServices<TBootstrapper>(this TBootstrapper
return bootstrapper;
}

public static TBootstrapper ConfigureEngine<TBootstrapper>(this TBootstrapper bootstrapper, Action<IEngine> action)
public static TBootstrapper ConfigureEngine<TBootstrapper>(
this TBootstrapper bootstrapper, Action<IEngine> action)
where TBootstrapper : IBootstrapper
{
bootstrapper.ThrowIfNull(nameof(bootstrapper));
action.ThrowIfNull(nameof(action));
bootstrapper.Configurators.Add<IEngine>(x => action(x));
bootstrapper.Configurators.Add(action);
return bootstrapper;
}
}
Expand Down

0 comments on commit 9c99d05

Please sign in to comment.