@@ -24,6 +24,13 @@ use std::time::Duration;
24
24
fn main ( ) {
25
25
println ! ( "Booting runner" ) ;
26
26
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 > {
27
34
let db_config = config:: DatabasePools :: full_from_environment ( ) ;
28
35
let base_config = config:: Base :: from_environment ( ) ;
29
36
let uploader = base_config. uploader ( ) ;
@@ -43,13 +50,13 @@ fn main() {
43
50
let job_start_timeout = dotenv:: var ( "BACKGROUND_JOB_TIMEOUT" )
44
51
. unwrap_or_else ( |_| "30" . into ( ) )
45
52
. parse ( )
46
- . expect ( "Invalid value for `BACKGROUND_JOB_TIMEOUT`" ) ;
53
+ . map_err ( |_| "Invalid value for `BACKGROUND_JOB_TIMEOUT`" ) ? ;
47
54
48
55
println ! ( "Cloning index" ) ;
49
56
50
57
let repository_config = RepositoryConfig :: from_environment ( ) ;
51
58
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" ) ? ,
53
60
) ) ;
54
61
println ! ( "Index cloned" ) ;
55
62
@@ -76,12 +83,12 @@ fn main() {
76
83
failure_count += 1 ;
77
84
if failure_count < 5 {
78
85
eprintln ! (
79
- "Error running jobs (n = {}) -- retrying: {:?}" ,
86
+ "at=error mod=background_worker error= \" Error running jobs (n = {}) -- retrying: {:?}\" " ,
80
87
failure_count, e,
81
88
) ;
82
89
runner = build_runner ( ) ;
83
90
} 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" ) ;
85
92
}
86
93
}
87
94
sleep ( Duration :: from_secs ( 1 ) ) ;
0 commit comments