@@ -16,9 +16,9 @@ use docs_rs::utils::{
1616    remove_crate_priority,  set_config,  set_crate_priority,  ConfigName , 
1717} ; 
1818use  docs_rs:: { 
19-     start_background_metrics_webserver,  start_web_server,  AsyncStorage ,   BuildQueue ,   Config , 
20-     Context ,  Index ,  InstanceMetrics ,  PackageKind ,  RegistryApi ,  RustwideBuilder ,   ServiceMetrics , 
21-     Storage , 
19+     start_background_metrics_webserver,  start_web_server,  AsyncBuildQueue ,   AsyncStorage , 
20+     BuildQueue ,   Config ,   Context ,  Index ,  InstanceMetrics ,  PackageKind ,  RegistryApi ,  RustwideBuilder , 
21+     ServiceMetrics ,   Storage , 
2222} ; 
2323use  futures_util:: StreamExt ; 
2424use  humantime:: Duration ; 
@@ -202,7 +202,14 @@ impl CommandLine {
202202
203203                start_background_metrics_webserver ( Some ( metric_server_socket_addr) ,  & ctx) ?; 
204204
205-                 docs_rs:: utils:: watch_registry ( ctx. build_queue ( ) ?,  ctx. config ( ) ?,  ctx. index ( ) ?) ?; 
205+                 ctx. runtime ( ) ?. block_on ( async  { 
206+                     docs_rs:: utils:: watch_registry ( 
207+                         ctx. async_build_queue ( ) . await ?, 
208+                         ctx. config ( ) ?, 
209+                         ctx. index ( ) ?, 
210+                     ) 
211+                     . await 
212+                 } ) ?; 
206213            } 
207214            Self :: StartBuildServer  { 
208215                metric_server_socket_addr, 
@@ -274,20 +281,21 @@ enum QueueSubcommand {
274281
275282impl  QueueSubcommand  { 
276283    fn  handle_args ( self ,  ctx :  BinContext )  -> Result < ( ) >  { 
284+         let  build_queue = ctx. build_queue ( ) ?; 
277285        match  self  { 
278286            Self :: Add  { 
279287                crate_name, 
280288                crate_version, 
281289                build_priority, 
282-             }  => ctx . build_queue ( ) ? . add_crate ( 
290+             }  => build_queue. add_crate ( 
283291                & crate_name, 
284292                & crate_version, 
285293                build_priority, 
286294                ctx. config ( ) ?. registry_url . as_deref ( ) , 
287295            ) ?, 
288296
289297            Self :: GetLastSeenReference  => { 
290-                 if  let  Some ( reference)  = ctx . build_queue ( ) ? . last_seen_reference ( ) ? { 
298+                 if  let  Some ( reference)  = build_queue. last_seen_reference ( ) ? { 
291299                    println ! ( "Last seen reference: {reference}" ) ; 
292300                }  else  { 
293301                    println ! ( "No last seen reference available" ) ; 
@@ -305,7 +313,7 @@ impl QueueSubcommand {
305313                    ( _,  _)  => unreachable ! ( ) , 
306314                } ; 
307315
308-                 ctx . build_queue ( ) ? . set_last_seen_reference ( reference) ?; 
316+                 build_queue. set_last_seen_reference ( reference) ?; 
309317                println ! ( "Set last seen reference: {reference}" ) ; 
310318            } 
311319
@@ -428,7 +436,6 @@ enum BuildSubcommand {
428436impl  BuildSubcommand  { 
429437    fn  handle_args ( self ,  ctx :  BinContext )  -> Result < ( ) >  { 
430438        let  build_queue = ctx. build_queue ( ) ?; 
431- 
432439        let  rustwide_builder = || -> Result < RustwideBuilder >  {  RustwideBuilder :: init ( & ctx)  } ; 
433440
434441        match  self  { 
@@ -817,6 +824,7 @@ enum DeleteSubcommand {
817824
818825struct  BinContext  { 
819826    build_queue :  OnceCell < Arc < BuildQueue > > , 
827+     async_build_queue :  tokio:: sync:: OnceCell < Arc < AsyncBuildQueue > > , 
820828    storage :  OnceCell < Arc < Storage > > , 
821829    cdn :  tokio:: sync:: OnceCell < Arc < CdnBackend > > , 
822830    config :  OnceCell < Arc < Config > > , 
@@ -833,6 +841,7 @@ impl BinContext {
833841    fn  new ( )  -> Self  { 
834842        Self  { 
835843            build_queue :  OnceCell :: new ( ) , 
844+             async_build_queue :  tokio:: sync:: OnceCell :: new ( ) , 
836845            storage :  OnceCell :: new ( ) , 
837846            cdn :  tokio:: sync:: OnceCell :: new ( ) , 
838847            config :  OnceCell :: new ( ) , 
@@ -864,11 +873,8 @@ impl Context for BinContext {
864873        fn  build_queue( self )  -> BuildQueue  = { 
865874            let  runtime = self . runtime( ) ?; 
866875            BuildQueue :: new( 
867-                 self . pool( ) ?, 
868-                 self . instance_metrics( ) ?, 
869-                 self . config( ) ?, 
870876                runtime. clone( ) , 
871-                 runtime. block_on( self . async_storage ( ) ) ?, 
877+                 runtime. block_on( self . async_build_queue ( ) ) ?
872878            ) 
873879        } ; 
874880        fn  storage( self )  -> Storage  = { 
@@ -880,8 +886,7 @@ impl Context for BinContext {
880886        } ; 
881887        fn  config( self )  -> Config  = Config :: from_env( ) ?; 
882888        fn  service_metrics( self )  -> ServiceMetrics  = { 
883-             let  runtime = self . runtime( ) ?; 
884-             ServiceMetrics :: new( runtime) ?
889+             ServiceMetrics :: new( ) ?
885890        } ; 
886891        fn  instance_metrics( self )  -> InstanceMetrics  = InstanceMetrics :: new( ) ?; 
887892        fn  runtime( self )  -> Runtime  = { 
@@ -928,6 +933,21 @@ impl Context for BinContext {
928933        ) ) 
929934    } 
930935
936+     async  fn  async_build_queue ( & self )  -> Result < Arc < AsyncBuildQueue > >  { 
937+         Ok ( self 
938+             . async_build_queue 
939+             . get_or_try_init ( || async  { 
940+                 Ok :: < _ ,  Error > ( Arc :: new ( AsyncBuildQueue :: new ( 
941+                     self . pool ( ) ?, 
942+                     self . instance_metrics ( ) ?, 
943+                     self . config ( ) ?, 
944+                     self . async_storage ( ) . await ?, 
945+                 ) ) ) 
946+             } ) 
947+             . await ?
948+             . clone ( ) ) 
949+     } 
950+ 
931951    async  fn  cdn ( & self )  -> Result < Arc < CdnBackend > >  { 
932952        let  config = self . config ( ) ?; 
933953        Ok ( self 
0 commit comments