File tree Expand file tree Collapse file tree 1 file changed +22
-7
lines changed Expand file tree Collapse file tree 1 file changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -243,15 +243,30 @@ async fn run_server(addr: SocketAddr) -> anyhow::Result<()> {
243
243
// spawning a background task that will run the scheduled jobs
244
244
// every JOB_PROCESSING_CADENCE_IN_SECS
245
245
task:: spawn ( async move {
246
- let pool = db:: ClientPool :: new ( ) ;
247
-
248
246
loop {
249
- db:: run_scheduled_jobs ( & * pool. get ( ) . await )
250
- . await
251
- . context ( "run database scheduled jobs" )
252
- . unwrap ( ) ;
247
+ let res = task:: spawn ( async move {
248
+ let pool = db:: ClientPool :: new ( ) ;
249
+
250
+ loop {
251
+ db:: run_scheduled_jobs ( & * pool. get ( ) . await )
252
+ . await
253
+ . context ( "run database scheduled jobs" )
254
+ . unwrap ( ) ;
253
255
254
- sleep ( Duration :: from_secs ( JOB_PROCESSING_CADENCE_IN_SECS ) ) . await ;
256
+ sleep ( Duration :: from_secs ( JOB_PROCESSING_CADENCE_IN_SECS ) ) . await ;
257
+ }
258
+ } ) ;
259
+
260
+ match res. await {
261
+ Err ( err) if err. is_panic ( ) => {
262
+ /* handle panic in above task, re-launching */
263
+ tracing:: trace!( "run_scheduled_jobs task died (error={})" , err) ;
264
+ }
265
+ _ => {
266
+ /* break in other case by default */
267
+ break ;
268
+ }
269
+ }
255
270
}
256
271
} ) ;
257
272
You can’t perform that action at this time.
0 commit comments