File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ public class Program
1515{
1616 private const int DefaultQueryTimeout = 300 ;
1717
18- public static async Task Main ( string [ ] args )
18+ public static async Task < int > Main ( string [ ] args )
1919 {
2020 var environment = Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) ;
2121 var configuration = new ConfigurationBuilder ( )
@@ -30,24 +30,30 @@ public static async Task Main(string[] args)
3030 . ReadFrom . Configuration ( configuration )
3131 . CreateLogger ( ) ;
3232
33- // Create and configure the host to support dependency injection, configuration, etc.
34- var consoleHost = CreateHostBuilder ( args ) . Build ( ) ;
35-
36- // Check if the database is ready for indexing.
37- var databasePreflightCheck = consoleHost . Services . GetRequiredService < DatabasePreflightCheck > ( ) ;
38- if ( ! databasePreflightCheck . IsGood ( ) )
33+ try
3934 {
40- return ;
41- }
35+ var consoleHost = CreateHostBuilder ( args ) . Build ( ) ;
4236
43- // Get the "Main" service which handles the indexing.
44- var indexer = consoleHost . Services . GetRequiredService < Indexer > ( ) ;
37+ var databasePreflightCheck = consoleHost . Services . GetRequiredService < DatabasePreflightCheck > ( ) ;
38+ if ( ! databasePreflightCheck . IsGood ( ) )
39+ {
40+ return 1 ;
41+ }
4542
46- // Start indexing.
47- await indexer . Start ( ) ;
43+ var indexer = consoleHost . Services . GetRequiredService < Indexer > ( ) ;
44+ await indexer . Start ( ) ;
4845
49- // Flush logs
50- Log . CloseAndFlush ( ) ;
46+ return 0 ;
47+ }
48+ catch ( Exception ex )
49+ {
50+ Log . Error ( ex , "Indexer failed" ) ;
51+ return 1 ;
52+ }
53+ finally
54+ {
55+ Log . CloseAndFlush ( ) ;
56+ }
5157 }
5258
5359 private static IHostBuilder CreateHostBuilder ( string [ ] args ) => Host
You can’t perform that action at this time.
0 commit comments