Skip to content

Commit 9c99d05

Browse files
committed
Allows configuring the engine manager
1 parent 1de2117 commit 9c99d05

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

RELEASE.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.0.0-beta.69
2+
3+
- 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).
4+
15
# 1.0.0-beta.68
26

37
- 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.

src/core/Statiq.App/Bootstrapper/BootstrapperConfigurationExtensions.cs

+12
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,17 @@ public static Bootstrapper AddConfigurator<TConfigurable>(
3737
bootstrapper.Configurators.Add(configurator);
3838
return bootstrapper;
3939
}
40+
41+
public static TBootstrapper ConfigureEngineManager<TBootstrapper>(
42+
this TBootstrapper bootstrapper, Action<IEngineManager> action)
43+
where TBootstrapper : IBootstrapper
44+
{
45+
bootstrapper.ThrowIfNull(nameof(bootstrapper));
46+
action.ThrowIfNull(nameof(action));
47+
bootstrapper.Configurators.Add(action);
48+
return bootstrapper;
49+
}
50+
51+
// Most of the Configure...() methods are in Statiq.Common if they configure a common interface
4052
}
4153
}

src/core/Statiq.App/Commands/EngineManager.cs

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public EngineManager(
2626
IServiceCollection serviceCollection,
2727
Bootstrapper bootstrapper)
2828
{
29+
Bootstrapper = bootstrapper;
30+
2931
// Get the standard input stream
3032
string input = null;
3133
if (commandSettings?.StdIn == true)
@@ -78,6 +80,8 @@ public EngineManager(
7880
_logger.LogInformation($"Cache path:{Environment.NewLine} {Engine.FileSystem.CachePath}");
7981
}
8082

83+
public IBootstrapper Bootstrapper { get; set; }
84+
8185
public Engine Engine { get; }
8286

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

8791
public async Task<ExitCode> ExecuteAsync(CancellationTokenSource cancellationTokenSource)
8892
{
93+
// Provide a chance to configure the engine manager, which is mainly useful for tweaking
94+
// the pipelines and/or engine right before executing
95+
Bootstrapper.Configurators.Configure<IEngineManager>(this);
96+
97+
// Execute the engine and log all errors (including cancellation requests)
8998
try
9099
{
91100
await Engine.ExecuteAsync(Pipelines, NormalPipelines, cancellationTokenSource?.Token ?? CancellationToken.None);
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System.Threading;
22
using System.Threading.Tasks;
3+
using Statiq.Common;
34
using Statiq.Core;
45

56
namespace Statiq.App
67
{
7-
public interface IEngineManager
8+
public interface IEngineManager : IConfigurable
89
{
910
Engine Engine { get; }
1011

@@ -14,4 +15,4 @@ public interface IEngineManager
1415

1516
Task<ExitCode> ExecuteAsync(CancellationTokenSource cancellationTokenSource);
1617
}
17-
}
18+
}

src/core/Statiq.Common/Bootstrapper/BootstrapperConfigurationExtensions.cs

+11-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ namespace Statiq.Common
66
{
77
public static class BootstrapperConfigurationExtensions
88
{
9-
public static TBootstrapper BuildConfiguration<TBootstrapper>(this TBootstrapper bootstrapper, Action<IConfigurationBuilder> action)
9+
public static TBootstrapper BuildConfiguration<TBootstrapper>(
10+
this TBootstrapper bootstrapper, Action<IConfigurationBuilder> action)
1011
where TBootstrapper : IBootstrapper
1112
{
1213
bootstrapper.ThrowIfNull(nameof(bootstrapper));
@@ -15,7 +16,8 @@ public static TBootstrapper BuildConfiguration<TBootstrapper>(this TBootstrapper
1516
return bootstrapper;
1617
}
1718

18-
public static TBootstrapper ConfigureServices<TBootstrapper>(this TBootstrapper bootstrapper, Action<IServiceCollection> action)
19+
public static TBootstrapper ConfigureServices<TBootstrapper>(
20+
this TBootstrapper bootstrapper, Action<IServiceCollection> action)
1921
where TBootstrapper : IBootstrapper
2022
{
2123
bootstrapper.ThrowIfNull(nameof(bootstrapper));
@@ -24,7 +26,8 @@ public static TBootstrapper ConfigureServices<TBootstrapper>(this TBootstrapper
2426
return bootstrapper;
2527
}
2628

27-
public static TBootstrapper ConfigureServices<TBootstrapper>(this TBootstrapper bootstrapper, Action<IServiceCollection, IReadOnlySettings> action)
29+
public static TBootstrapper ConfigureServices<TBootstrapper>(
30+
this TBootstrapper bootstrapper, Action<IServiceCollection, IReadOnlySettings> action)
2831
where TBootstrapper : IBootstrapper
2932
{
3033
bootstrapper.ThrowIfNull(nameof(bootstrapper));
@@ -33,7 +36,8 @@ public static TBootstrapper ConfigureServices<TBootstrapper>(this TBootstrapper
3336
return bootstrapper;
3437
}
3538

36-
public static TBootstrapper ConfigureServices<TBootstrapper>(this TBootstrapper bootstrapper, Action<IServiceCollection, IReadOnlySettings, IReadOnlyFileSystem> action)
39+
public static TBootstrapper ConfigureServices<TBootstrapper>(
40+
this TBootstrapper bootstrapper, Action<IServiceCollection, IReadOnlySettings, IReadOnlyFileSystem> action)
3741
where TBootstrapper : IBootstrapper
3842
{
3943
bootstrapper.ThrowIfNull(nameof(bootstrapper));
@@ -42,12 +46,13 @@ public static TBootstrapper ConfigureServices<TBootstrapper>(this TBootstrapper
4246
return bootstrapper;
4347
}
4448

45-
public static TBootstrapper ConfigureEngine<TBootstrapper>(this TBootstrapper bootstrapper, Action<IEngine> action)
49+
public static TBootstrapper ConfigureEngine<TBootstrapper>(
50+
this TBootstrapper bootstrapper, Action<IEngine> action)
4651
where TBootstrapper : IBootstrapper
4752
{
4853
bootstrapper.ThrowIfNull(nameof(bootstrapper));
4954
action.ThrowIfNull(nameof(action));
50-
bootstrapper.Configurators.Add<IEngine>(x => action(x));
55+
bootstrapper.Configurators.Add(action);
5156
return bootstrapper;
5257
}
5358
}

0 commit comments

Comments
 (0)