Skip to content

Commit 621b482

Browse files
authored
rs/update verse reporting processor (#194)
* Configurably split the DB/PORT sending logic * Make things more the way I want them to be
1 parent 516e627 commit 621b482

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

VerseReportingProcessor/VerseCounterService.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class VerseCounterService: IHostedService
3333
private readonly VerseProcessorMetrics _metrics;
3434
private readonly OrganizationServiceFactory _organizationServiceFactory;
3535
private readonly SemaphoreSlim _databaseSemaphore = new(1, 1);
36+
private readonly bool _enableDatabasePush;
37+
private readonly bool _enablePortPush;
3638

3739
public VerseCounterService(IConfiguration config, ILogger<VerseCounterService> log, IMemoryCache cache, VerseProcessorMetrics metrics, OrganizationServiceFactory organizationServiceFactory)
3840
{
@@ -42,6 +44,8 @@ public VerseCounterService(IConfiguration config, ILogger<VerseCounterService> l
4244
_activitySource = new ActivitySource(nameof(VerseCounterService));
4345
_metrics = metrics;
4446
_organizationServiceFactory = organizationServiceFactory;
47+
_enableDatabasePush = config.GetValue("EnableDatabasePush", true);
48+
_enablePortPush = config.GetValue("EnablePortPush", true);
4549
}
4650

4751
public async Task StartAsync(CancellationToken cancellationToken)
@@ -69,13 +73,15 @@ public async Task StartAsync(CancellationToken cancellationToken)
6973
}
7074
_log.LogInformation("Processing {RepoId} {User}/{Repo}", input.RepoId.ToString(), input.User, input.Repo);
7175
var result = Calculate(input, await GetCountDefinitionsAsync(input.LanguageCode));
72-
var dbTask = SendUpsertToDatabaseAsync(result);
73-
74-
75-
var service = await _organizationServiceFactory.GetServiceClientAsync();
76-
var portTask = UpsertIntoPORT(service, result);
77-
78-
await Task.WhenAll(dbTask, portTask);
76+
var tasks = new List<Task>();
77+
if (_enableDatabasePush)
78+
tasks.Add(SendUpsertToDatabaseAsync(result));
79+
if (_enablePortPush)
80+
{
81+
var service = await _organizationServiceFactory.GetServiceClientAsync();
82+
tasks.Add(UpsertIntoPORT(service, result));
83+
}
84+
await Task.WhenAll(tasks);
7985

8086
_metrics.ReposProcessed(1);
8187
await args.CompleteMessageAsync(args.Message, cancellationToken);
@@ -98,9 +104,12 @@ public async Task StartAsync(CancellationToken cancellationToken)
98104
throw new Exception("Invalid message received");
99105
}
100106

101-
_log.LogInformation("Processing delete for {RepoId} {User}/{Repo}", input.RepoId.ToString(), input.Repo,
102-
input.User);
103-
await SendDeleteToDatabaseAsync(input.RepoId);
107+
_log.LogInformation("Processing delete for {RepoId} {User}/{Repo}", input.RepoId.ToString(), input.User,
108+
input.Repo);
109+
if (_enableDatabasePush)
110+
{
111+
await SendDeleteToDatabaseAsync(input.RepoId);
112+
}
104113
};
105114

106115
_deleteProcessor.ProcessErrorAsync += args =>

VerseReportingProcessor/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
- ConnectionStrings__BlobStorage
99
- ConnectionStrings__Dataverse
1010
- MaxServiceBusConnections
11+
- EnableDatabasePush
12+
- EnablePortPush
1113
- APPLICATIONINSIGHTS_CONNECTION_STRING

0 commit comments

Comments
 (0)