@@ -24,6 +24,13 @@ use std::time::Duration;
2424fn main ( ) {
2525 println ! ( "Booting runner" ) ;
2626
27+ if let Err ( message) = main_impl ( ) {
28+ eprintln ! ( "at=error mod=background_worker error=\" {}\" " , message) ;
29+ std:: process:: exit ( 1 ) ;
30+ }
31+ }
32+
33+ fn main_impl ( ) -> Result < ( ) , & ' static str > {
2734 let db_config = config:: DatabasePools :: full_from_environment ( ) ;
2835 let base_config = config:: Base :: from_environment ( ) ;
2936 let uploader = base_config. uploader ( ) ;
@@ -43,13 +50,13 @@ fn main() {
4350 let job_start_timeout = dotenv:: var ( "BACKGROUND_JOB_TIMEOUT" )
4451 . unwrap_or_else ( |_| "30" . into ( ) )
4552 . parse ( )
46- . expect ( "Invalid value for `BACKGROUND_JOB_TIMEOUT`" ) ;
53+ . map_err ( |_| "Invalid value for `BACKGROUND_JOB_TIMEOUT`" ) ? ;
4754
4855 println ! ( "Cloning index" ) ;
4956
5057 let repository_config = RepositoryConfig :: from_environment ( ) ;
5158 let repository = Arc :: new ( Mutex :: new (
52- Repository :: open ( & repository_config) . expect ( "Failed to clone index" ) ,
59+ Repository :: open ( & repository_config) . map_err ( |_| "Failed to clone index" ) ? ,
5360 ) ) ;
5461 println ! ( "Index cloned" ) ;
5562
@@ -76,12 +83,12 @@ fn main() {
7683 failure_count += 1 ;
7784 if failure_count < 5 {
7885 eprintln ! (
79- "Error running jobs (n = {}) -- retrying: {:?}" ,
86+ "at=error mod=background_worker error= \" Error running jobs (n = {}) -- retrying: {:?}\" " ,
8087 failure_count, e,
8188 ) ;
8289 runner = build_runner ( ) ;
8390 } else {
84- panic ! ( "Failed to begin running jobs 5 times. Restarting the process" ) ;
91+ return Err ( "Failed to begin running jobs 5 times. Restarting the process" ) ;
8592 }
8693 }
8794 sleep ( Duration :: from_secs ( 1 ) ) ;
0 commit comments