@@ -9,7 +9,7 @@ mod reorg_handler;
99use std:: time:: { Duration , Instant } ;
1010
1111use anyhow:: Result ;
12- use futures:: { future :: BoxFuture , StreamExt } ;
12+ use futures:: StreamExt ;
1313use graph:: {
1414 amp:: Client , cheap_clone:: CheapClone , components:: store:: EntityCache ,
1515 data:: subgraph:: schema:: SubgraphError ,
@@ -24,48 +24,45 @@ use self::{
2424
2525pub ( super ) use self :: context:: Context ;
2626
27- pub ( super ) fn new_runner < AC > (
27+ pub ( super ) async fn new_runner < AC > (
2828 mut cx : Context < AC > ,
29- ) -> Box < dyn FnOnce ( CancellationToken ) -> BoxFuture < ' static , Result < ( ) > > + Send + ' static >
29+ cancel_token : CancellationToken ,
30+ ) -> Result < ( ) >
3031where
3132 AC : Client + Send + Sync + ' static ,
3233{
33- Box :: new ( move |cancel_token| {
34- Box :: pin ( async move {
35- let indexing_duration_handle = tokio:: spawn ( {
36- let mut instant = Instant :: now ( ) ;
37- let indexing_duration = cx. metrics . indexing_duration . clone ( ) ;
38-
39- async move {
40- loop {
41- tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
42-
43- let prev_instant = std:: mem:: replace ( & mut instant, Instant :: now ( ) ) ;
44- indexing_duration. record ( prev_instant. elapsed ( ) ) ;
45- }
46- }
47- } ) ;
48-
49- let result = cancel_token
50- . run_until_cancelled ( run_indexing_with_retries ( & mut cx) )
51- . await ;
34+ let indexing_duration_handle = tokio:: spawn ( {
35+ let mut instant = Instant :: now ( ) ;
36+ let indexing_duration = cx. metrics . indexing_duration . clone ( ) ;
5237
53- indexing_duration_handle. abort ( ) ;
38+ async move {
39+ loop {
40+ tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
5441
55- match result {
56- Some ( result) => result?,
57- None => {
58- debug ! ( cx. logger, "Processed cancel signal" ) ;
59- }
42+ let prev_instant = std:: mem:: replace ( & mut instant, Instant :: now ( ) ) ;
43+ indexing_duration. record ( prev_instant. elapsed ( ) ) ;
6044 }
45+ }
46+ } ) ;
47+
48+ let result = cancel_token
49+ . run_until_cancelled ( run_indexing_with_retries ( & mut cx) )
50+ . await ;
51+
52+ indexing_duration_handle. abort ( ) ;
53+
54+ match result {
55+ Some ( result) => result?,
56+ None => {
57+ debug ! ( cx. logger, "Processed cancel signal" ) ;
58+ }
59+ }
6160
62- cx. metrics . deployment_status . stopped ( ) ;
61+ cx. metrics . deployment_status . stopped ( ) ;
6362
64- debug ! ( cx. logger, "Waiting for the store to finish processing" ) ;
65- cx. store . flush ( ) . await ?;
66- Ok ( ( ) )
67- } )
68- } )
63+ debug ! ( cx. logger, "Waiting for the store to finish processing" ) ;
64+ cx. store . flush ( ) . await ?;
65+ Ok ( ( ) )
6966}
7067
7168async fn run_indexing < AC > ( cx : & mut Context < AC > ) -> Result < ( ) , Error >
0 commit comments