@@ -16,9 +16,9 @@ use docs_rs::utils::{
16
16
remove_crate_priority, set_config, set_crate_priority, ConfigName ,
17
17
} ;
18
18
use 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 ,
22
22
} ;
23
23
use futures_util:: StreamExt ;
24
24
use humantime:: Duration ;
@@ -202,7 +202,14 @@ impl CommandLine {
202
202
203
203
start_background_metrics_webserver ( Some ( metric_server_socket_addr) , & ctx) ?;
204
204
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
+ } ) ?;
206
213
}
207
214
Self :: StartBuildServer {
208
215
metric_server_socket_addr,
@@ -274,20 +281,21 @@ enum QueueSubcommand {
274
281
275
282
impl QueueSubcommand {
276
283
fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
284
+ let build_queue = ctx. build_queue ( ) ?;
277
285
match self {
278
286
Self :: Add {
279
287
crate_name,
280
288
crate_version,
281
289
build_priority,
282
- } => ctx . build_queue ( ) ? . add_crate (
290
+ } => build_queue. add_crate (
283
291
& crate_name,
284
292
& crate_version,
285
293
build_priority,
286
294
ctx. config ( ) ?. registry_url . as_deref ( ) ,
287
295
) ?,
288
296
289
297
Self :: GetLastSeenReference => {
290
- if let Some ( reference) = ctx . build_queue ( ) ? . last_seen_reference ( ) ? {
298
+ if let Some ( reference) = build_queue. last_seen_reference ( ) ? {
291
299
println ! ( "Last seen reference: {reference}" ) ;
292
300
} else {
293
301
println ! ( "No last seen reference available" ) ;
@@ -305,7 +313,7 @@ impl QueueSubcommand {
305
313
( _, _) => unreachable ! ( ) ,
306
314
} ;
307
315
308
- ctx . build_queue ( ) ? . set_last_seen_reference ( reference) ?;
316
+ build_queue. set_last_seen_reference ( reference) ?;
309
317
println ! ( "Set last seen reference: {reference}" ) ;
310
318
}
311
319
@@ -428,7 +436,6 @@ enum BuildSubcommand {
428
436
impl BuildSubcommand {
429
437
fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
430
438
let build_queue = ctx. build_queue ( ) ?;
431
-
432
439
let rustwide_builder = || -> Result < RustwideBuilder > { RustwideBuilder :: init ( & ctx) } ;
433
440
434
441
match self {
@@ -817,6 +824,7 @@ enum DeleteSubcommand {
817
824
818
825
struct BinContext {
819
826
build_queue : OnceCell < Arc < BuildQueue > > ,
827
+ async_build_queue : tokio:: sync:: OnceCell < Arc < AsyncBuildQueue > > ,
820
828
storage : OnceCell < Arc < Storage > > ,
821
829
cdn : tokio:: sync:: OnceCell < Arc < CdnBackend > > ,
822
830
config : OnceCell < Arc < Config > > ,
@@ -833,6 +841,7 @@ impl BinContext {
833
841
fn new ( ) -> Self {
834
842
Self {
835
843
build_queue : OnceCell :: new ( ) ,
844
+ async_build_queue : tokio:: sync:: OnceCell :: new ( ) ,
836
845
storage : OnceCell :: new ( ) ,
837
846
cdn : tokio:: sync:: OnceCell :: new ( ) ,
838
847
config : OnceCell :: new ( ) ,
@@ -864,11 +873,8 @@ impl Context for BinContext {
864
873
fn build_queue( self ) -> BuildQueue = {
865
874
let runtime = self . runtime( ) ?;
866
875
BuildQueue :: new(
867
- self . pool( ) ?,
868
- self . instance_metrics( ) ?,
869
- self . config( ) ?,
870
876
runtime. clone( ) ,
871
- runtime. block_on( self . async_storage ( ) ) ?,
877
+ runtime. block_on( self . async_build_queue ( ) ) ?
872
878
)
873
879
} ;
874
880
fn storage( self ) -> Storage = {
@@ -880,8 +886,7 @@ impl Context for BinContext {
880
886
} ;
881
887
fn config( self ) -> Config = Config :: from_env( ) ?;
882
888
fn service_metrics( self ) -> ServiceMetrics = {
883
- let runtime = self . runtime( ) ?;
884
- ServiceMetrics :: new( runtime) ?
889
+ ServiceMetrics :: new( ) ?
885
890
} ;
886
891
fn instance_metrics( self ) -> InstanceMetrics = InstanceMetrics :: new( ) ?;
887
892
fn runtime( self ) -> Runtime = {
@@ -928,6 +933,21 @@ impl Context for BinContext {
928
933
) )
929
934
}
930
935
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
+
931
951
async fn cdn ( & self ) -> Result < Arc < CdnBackend > > {
932
952
let config = self . config ( ) ?;
933
953
Ok ( self
0 commit comments