Skip to content

Commit

Permalink
add ability to disable specific generators by name
Browse files Browse the repository at this point in the history
  • Loading branch information
aspriddell committed Oct 14, 2023
1 parent 61a018f commit 95efb6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions DragonFruit.OnionFruit.Web.Worker/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Worker(IServiceScopeFactory ssf, IConfiguration config, ILogger<Worker> l
_stopwatch = new Stopwatch();

_exporters = GetExporters(config);
_descriptors = GetDescriptors();
_descriptors = GetDescriptors(config);
}

private async Task PerformUpdate()
Expand Down Expand Up @@ -156,13 +156,19 @@ private async Task PerformUpdate()
await redis.StringSetAsync(LastDatabaseVersionKey, nextVersion, TimeSpan.FromDays(1)).ConfigureAwait(false);
}

private IReadOnlyCollection<GeneratorDescriptor> GetDescriptors()
private IReadOnlyCollection<GeneratorDescriptor> GetDescriptors(IConfiguration config)
{
var listing = new List<GeneratorDescriptor>();

// get all file generators, determine what generators need what types
foreach (var fileGeneratorType in GetType().Assembly.ExportedTypes.Where(x => x.IsAssignableTo(typeof(IDatabaseGenerator))))
{
if (config.GetSection("EnabledGenerators").GetValue<string>(fileGeneratorType.Name)?.Equals("false", StringComparison.OrdinalIgnoreCase) == true)
{
_logger.LogInformation("{gen} was disabled by configuration", fileGeneratorType.Name);
continue;
}

var ctor = fileGeneratorType.GetConstructors().SingleOrDefault();

if (ctor == null)
Expand Down
4 changes: 4 additions & 0 deletions DragonFruit.OnionFruit.Web.Worker/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"Redis": {
"ConnectionString": ""
},
"EnabledGenerators": {
"OnionLiteDbGenerator": "false",
"RedisDatabaseGenerator": "true"
},
"Exports": {
}
}

0 comments on commit 95efb6b

Please sign in to comment.