mononoke: asyncify BundlePreparer constructor

Reviewed By: aslpavel

Differential Revision: D25185048

fbshipit-source-id: 251bca9e6693151e889520e0a40a8051e824d4f7
This commit is contained in:
Stanislau Hlebik 2020-11-27 02:20:12 -08:00 committed by Facebook GitHub Bot
parent f10d77ce5d
commit d856af393a
2 changed files with 20 additions and 25 deletions

View File

@ -18,7 +18,6 @@ use futures::{
future::{try_join, FutureExt as _, TryFutureExt},
};
use futures_ext::{BoxFuture, FutureExt};
use futures_old::{future::ok, Future};
use getbundle_response::SessionLfsParams;
use itertools::Itertools;
use mercurial_bundle_replay_data::BundleReplayData;
@ -66,12 +65,12 @@ enum BundleType {
}
impl BundlePreparer {
pub fn new_use_existing(
pub async fn new_use_existing(
repo: BlobRepo,
base_retry_delay_ms: u64,
retry_num: usize,
) -> impl Future<Item = BundlePreparer, Error = Error> {
ok(BundlePreparer {
) -> Result<BundlePreparer, Error> {
Ok(BundlePreparer {
repo,
base_retry_delay_ms,
retry_num,
@ -79,7 +78,7 @@ impl BundlePreparer {
})
}
pub fn new_generate_bundles(
pub async fn new_generate_bundles(
ctx: CoreContext,
repo: BlobRepo,
base_retry_delay_ms: u64,
@ -88,25 +87,23 @@ impl BundlePreparer {
lfs_params: LfsParams,
filenode_verifier: FilenodeVerifier,
bookmark_regex_force_lfs: Option<Regex>,
) -> impl Future<Item = BundlePreparer, Error = Error> {
) -> Result<BundlePreparer, Error> {
let blobstore = repo.get_blobstore().boxed();
async move { fetch_skiplist_index(&ctx, &maybe_skiplist_blobstore_key, &blobstore).await }
.boxed()
.compat()
.map(move |skiplist| {
let lca_hint: Arc<dyn LeastCommonAncestorsHint> = skiplist;
BundlePreparer {
repo,
base_retry_delay_ms,
retry_num,
ty: BundleType::GenerateNew {
lca_hint,
lfs_params,
filenode_verifier,
bookmark_regex_force_lfs,
},
}
})
let skiplist =
fetch_skiplist_index(&ctx, &maybe_skiplist_blobstore_key, &blobstore).await?;
let lca_hint: Arc<dyn LeastCommonAncestorsHint> = skiplist;
Ok(BundlePreparer {
repo,
base_retry_delay_ms,
retry_num,
ty: BundleType::GenerateNew {
lca_hint,
lfs_params,
filenode_verifier,
bookmark_regex_force_lfs,
},
})
}
pub fn prepare_single_bundle(

View File

@ -703,12 +703,10 @@ async fn run(ctx: CoreContext, matches: ArgMatches<'static>) -> Result<(), Error
filenode_verifier,
bookmark_regex_force_lfs,
)
.compat()
.map_ok(Arc::new)
.await
} else {
BundlePreparer::new_use_existing(repo.clone(), base_retry_delay_ms, retry_num)
.compat()
.map_ok(Arc::new)
.await
}