Create multiple assets concurrently #5

Merged
Quaternions merged 16 commits from staging into master 2024-08-17 18:00:28 +00:00
Showing only changes of commit 136dbb3054 - Show all commits

View File

@ -727,6 +727,7 @@ async fn create_asset_medias(config:CreateAssetMediasConfig)->AResult<()>{
let description=&config.description;
let creator=&config.creator;
let context=&context;
async move{(path.clone(),
async move{
let model_name=path.file_stem()
.and_then(std::ffi::OsStr::to_str)
@ -752,20 +753,24 @@ async fn create_asset_medias(config:CreateAssetMediasConfig)->AResult<()>{
}
},file).await.map_err(CreateAssetMediasError::Create)
}
.await)}
}))
//parallel requests
.buffer_unordered(CONCURRENT_REQUESTS)
//step 2: poll operation until it completes
.then(|create_result|{
.then(|(path,create_result)|{
let context=&context;
async{(path,
async{
let create_asset_response=create_result.map_err(PollOperationError::CreateAssetMedias)?;
get_asset_exp_backoff(context,&create_asset_response).await.map_err(PollOperationError::CreateAssetResponseGetAsset)
}
.await)}
})
//step 3: read decal id from operation and download it, decode it as a roblox file and extract the texture content url
.then(|asset_response_result|{
.then(|(path,asset_response_result)|{
let cookie_context=&cookie_context;
async move{(path,
async move{
let asset_response=asset_response_result.map_err(DownloadDecalError::PollOperation)?;
let file=cookie_context.get_asset(rbx_asset::cookie::GetAssetRequest{
@ -783,11 +788,12 @@ async fn create_asset_medias(config:CreateAssetMediasConfig)->AResult<()>{
};
Ok::<_,DownloadDecalError>((asset_response.displayName,asset_url))
}
.await)}
})
.for_each(|download_decal_result|async{
.for_each(|(path,download_decal_result)|async move{
match download_decal_result{
Ok((file_name,asset_url))=>println!("{}={}",file_name,asset_url),
Err(e)=>eprintln!("ERROR error={e}"),
Err(e)=>eprintln!("ERROR file={:?} error={e}",path),
}
}).await;
Ok(())