Skip to content

Commit 0e10dad

Browse files
author
Guy Fankam
committed
Prioritize backend processing
1 parent d93572a commit 0e10dad

2 files changed

Lines changed: 48 additions & 8 deletions

File tree

tools/code/publisher/App.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace publisher;
1515

1616
file sealed class RunPublisherHandler(ProcessNamedValuesToPut processNamedValuesToPut,
1717
ProcessDeletedNamedValues processDeletedNamedValues,
18+
ProcessBackendsToPut processBackendsToPut,
19+
ProcessDeletedBackends processDeletedBackends,
1820
GetPublisherFiles getPublisherFiles,
1921
PublishFile publishFile,
2022
ILoggerFactory loggerFactory)
@@ -24,10 +26,12 @@ file sealed class RunPublisherHandler(ProcessNamedValuesToPut processNamedValues
2426
public async ValueTask Handle(CancellationToken cancellationToken)
2527
{
2628
await processNamedValuesToPut(cancellationToken);
29+
await processBackendsToPut(cancellationToken);
2730

2831
await ProcessPublisherFiles(cancellationToken);
2932

3033
await processDeletedNamedValues(cancellationToken);
34+
await processDeletedBackends(cancellationToken);
3135

3236
logger.LogInformation("Publisher completed.");
3337
}
@@ -47,7 +51,6 @@ private async ValueTask ProcessPublisherFiles(CancellationToken cancellationToke
4751
file sealed class PublishFileHandler(FindTagAction findTagAction,
4852
FindGatewayAction findGatewayAction,
4953
FindVersionSetAction findVersionSetAction,
50-
FindBackendAction findBackendAction,
5154
FindLoggerAction findLoggerAction,
5255
FindDiagnosticAction findDiagnosticAction,
5356
FindPolicyFragmentAction findPolicyFragmentAction,
@@ -75,7 +78,6 @@ private Option<PublisherAction> FindPublisherAction(FileInfo file) =>
7578
findTagAction(file)
7679
| findGatewayAction(file)
7780
| findVersionSetAction(file)
78-
| findBackendAction(file)
7981
| findLoggerAction(file)
8082
| findDiagnosticAction(file)
8183
| findPolicyFragmentAction(file)
@@ -100,6 +102,8 @@ public static void ConfigureRunPublisher(IServiceCollection services)
100102
{
101103
NamedValueServices.ConfigureProcessNamedValuesToPut(services);
102104
NamedValueServices.ConfigureProcessDeletedNamedValues(services);
105+
BackendServices.ConfigureProcessBackendsToPut(services);
106+
BackendServices.ConfigureProcessDeletedBackends(services);
103107
ConfigurePublishFile(services);
104108

105109
services.TryAddSingleton<RunPublisherHandler>();
@@ -111,7 +115,6 @@ private static void ConfigurePublishFile(IServiceCollection services)
111115
TagServices.ConfigureFindTagAction(services);
112116
GatewayServices.ConfigureFindGatewayAction(services);
113117
VersionSetServices.ConfigureFindVersionSetAction(services);
114-
BackendServices.ConfigureFindBackendAction(services);
115118
LoggerServices.ConfigureFindLoggerAction(services);
116119
DiagnosticServices.ConfigureFindDiagnosticAction(services);
117120
PolicyFragmentServices.ConfigureFindPolicyFragmentAction(services);

tools/code/publisher/Backend.cs

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
using System.Collections.Generic;
1010
using System.Collections.Immutable;
1111
using System.IO;
12+
using System.Linq;
1213
using System.Threading;
1314
using System.Threading.Tasks;
1415

1516
namespace publisher;
1617

17-
internal delegate Option<PublisherAction> FindBackendAction(FileInfo file);
18+
internal delegate ValueTask ProcessBackendsToPut(CancellationToken cancellationToken);
19+
internal delegate ValueTask ProcessDeletedBackends(CancellationToken cancellationToken);
1820

1921
file delegate Option<BackendName> TryParseBackendName(FileInfo file);
2022

@@ -32,6 +34,30 @@ namespace publisher;
3234

3335
file delegate ValueTask DeleteBackendFromApim(BackendName name, CancellationToken cancellationToken);
3436

37+
file sealed class ProcessBackendsToPutHandler(GetPublisherFiles getPublisherFiles,
38+
TryParseBackendName tryParseBackendName,
39+
IsBackendNameInSourceControl isNameInSourceControl,
40+
PutBackend putBackend)
41+
{
42+
public async ValueTask Handle(CancellationToken cancellationToken) =>
43+
await getPublisherFiles()
44+
.Choose(tryParseBackendName.Invoke)
45+
.Where(isNameInSourceControl.Invoke)
46+
.IterParallel(putBackend.Invoke, cancellationToken);
47+
}
48+
49+
file sealed class ProcessDeletedBackendsHandler(GetPublisherFiles getPublisherFiles,
50+
TryParseBackendName tryParseBackendName,
51+
IsBackendNameInSourceControl isNameInSourceControl,
52+
DeleteBackend deleteBackend)
53+
{
54+
public async ValueTask Handle(CancellationToken cancellationToken) =>
55+
await getPublisherFiles()
56+
.Choose(tryParseBackendName.Invoke)
57+
.Where(name => isNameInSourceControl(name) is false)
58+
.IterParallel(deleteBackend.Invoke, cancellationToken);
59+
}
60+
3561
file sealed class FindBackendActionHandler(TryParseBackendName tryParseName, ProcessBackend processBackend)
3662
{
3763
public Option<PublisherAction> Handle(FileInfo file) =>
@@ -189,13 +215,14 @@ public async ValueTask Handle(BackendName name, CancellationToken cancellationTo
189215

190216
internal static class BackendServices
191217
{
192-
public static void ConfigureFindBackendAction(IServiceCollection services)
218+
public static void ConfigureProcessBackendsToPut(IServiceCollection services)
193219
{
194220
ConfigureTryParseBackendName(services);
195-
ConfigureProcessBackend(services);
221+
ConfigureIsBackendNameInSourceControl(services);
222+
ConfigurePutBackend(services);
196223

197-
services.TryAddSingleton<FindBackendActionHandler>();
198-
services.TryAddSingleton<FindBackendAction>(provider => provider.GetRequiredService<FindBackendActionHandler>().Handle);
224+
services.TryAddSingleton<ProcessBackendsToPutHandler>();
225+
services.TryAddSingleton<ProcessBackendsToPut>(provider => provider.GetRequiredService<ProcessBackendsToPutHandler>().Handle);
199226
}
200227

201228
private static void ConfigureTryParseBackendName(IServiceCollection services)
@@ -241,6 +268,16 @@ private static void ConfigurePutBackendInApim(IServiceCollection services)
241268
services.TryAddSingleton<PutBackendInApim>(provider => provider.GetRequiredService<PutBackendInApimHandler>().Handle);
242269
}
243270

271+
public static void ConfigureProcessDeletedBackends(IServiceCollection services)
272+
{
273+
ConfigureTryParseBackendName(services);
274+
ConfigureIsBackendNameInSourceControl(services);
275+
ConfigureDeleteBackend(services);
276+
277+
services.TryAddSingleton<ProcessDeletedBackendsHandler>();
278+
services.TryAddSingleton<ProcessDeletedBackends>(provider => provider.GetRequiredService<ProcessDeletedBackendsHandler>().Handle);
279+
}
280+
244281
private static void ConfigureDeleteBackend(IServiceCollection services)
245282
{
246283
ConfigureDeleteBackendFromApim(services);

0 commit comments

Comments
 (0)