1- use crate :: manifest:: { Manifest , ManifestSource } ;
21use crate :: storage_backend:: { BoxedStorageBackend , StorageBackend } ;
2+ use miette:: IntoDiagnostic ;
33use moon_blob:: { BlobCleanStats , BlobContent , BlobInput , BlobOutput } ;
44use moon_common:: { Id , format_error_chain, is_daemon_env} ;
55use moon_config:: { CacheConfig , RemoteConfig } ;
66use moon_hash:: Digest ;
7+ use moon_manifest:: Manifest ;
78use rustc_hash:: FxHashMap ;
89use std:: collections:: VecDeque ;
910use std:: path:: PathBuf ;
1011use std:: sync:: Arc ;
11- use std:: sync:: Mutex ;
1212use std:: time:: { Duration , SystemTime } ;
13+ use tokio:: sync:: Mutex ;
1314use tokio:: task:: { AbortHandle , JoinHandle , JoinSet } ;
1415use tracing:: { debug, warn} ;
1516
@@ -19,6 +20,12 @@ use tracing::{debug, warn};
1920/// aborted and reported, and simply get re-uploaded on the next run.
2021const BACKGROUND_FLUSH_TIMEOUT : Duration = Duration :: from_secs ( 60 ) ;
2122
23+ pub struct ManifestSource {
24+ pub backend : BoxedStorageBackend ,
25+ pub manifest : Manifest ,
26+ pub remote : bool ,
27+ }
28+
2229#[ derive( Clone , Debug ) ]
2330pub struct CacheContext {
2431 pub cache_dir : PathBuf ,
@@ -222,7 +229,7 @@ impl Storage {
222229 }
223230
224231 pub async fn store_blobs ( & self , blobs : Vec < BlobInput > ) -> miette:: Result < ( ) > {
225- let mut background_tasks = self . background_tasks . lock ( ) . unwrap ( ) ;
232+ let mut background_tasks = self . background_tasks . lock ( ) . await ;
226233
227234 for backend in self . get_backends ( ) {
228235 if !backend. is_writable ( ) {
@@ -282,7 +289,7 @@ impl Storage {
282289 digest : & Digest ,
283290 manifest : Manifest ,
284291 ) -> miette:: Result < ( ) > {
285- let mut background_tasks = self . background_tasks . lock ( ) . unwrap ( ) ;
292+ let mut background_tasks = self . background_tasks . lock ( ) . await ;
286293
287294 debug ! (
288295 hash = digest. hash. as_str( ) ,
@@ -316,6 +323,10 @@ impl Storage {
316323 }
317324 }
318325
326+ while let Some ( result) = set. join_next ( ) . await {
327+ result. into_diagnostic ( ) ??;
328+ }
329+
319330 debug ! (
320331 hash = digest. hash. as_str( ) ,
321332 files = manifest. files. len( ) ,
@@ -403,7 +414,7 @@ impl Storage {
403414 /// backend, so the next run resolves locally instead of round-tripping to
404415 /// the remote.
405416 async fn warm_local_backends ( & self , digest : & Digest , manifest : & Manifest ) {
406- let mut background_tasks = self . background_tasks . lock ( ) . unwrap ( ) ;
417+ let mut background_tasks = self . background_tasks . lock ( ) . await ;
407418
408419 for backend in self . get_local_backends ( ) {
409420 if !backend. is_writable ( ) {
@@ -432,7 +443,7 @@ impl Storage {
432443 let background_tasks = {
433444 self . background_tasks
434445 . lock ( )
435- . unwrap ( )
446+ . await
436447 . drain ( 0 ..)
437448 . collect :: < Vec < _ > > ( )
438449 } ;
0 commit comments