@@ -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 =>
0 commit comments