Create multiple assets concurrently #5
14
src/main.rs
14
src/main.rs
@ -727,6 +727,7 @@ async fn create_asset_medias(config:CreateAssetMediasConfig)->AResult<()>{
|
|||||||
let description=&config.description;
|
let description=&config.description;
|
||||||
let creator=&config.creator;
|
let creator=&config.creator;
|
||||||
let context=&context;
|
let context=&context;
|
||||||
|
async move{(path.clone(),
|
||||||
async move{
|
async move{
|
||||||
let model_name=path.file_stem()
|
let model_name=path.file_stem()
|
||||||
.and_then(std::ffi::OsStr::to_str)
|
.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)
|
},file).await.map_err(CreateAssetMediasError::Create)
|
||||||
}
|
}
|
||||||
|
.await)}
|
||||||
}))
|
}))
|
||||||
//parallel requests
|
//parallel requests
|
||||||
.buffer_unordered(CONCURRENT_REQUESTS)
|
.buffer_unordered(CONCURRENT_REQUESTS)
|
||||||
//step 2: poll operation until it completes
|
//step 2: poll operation until it completes
|
||||||
.then(|create_result|{
|
.then(|(path,create_result)|{
|
||||||
let context=&context;
|
let context=&context;
|
||||||
|
async{(path,
|
||||||
async{
|
async{
|
||||||
let create_asset_response=create_result.map_err(PollOperationError::CreateAssetMedias)?;
|
let create_asset_response=create_result.map_err(PollOperationError::CreateAssetMedias)?;
|
||||||
get_asset_exp_backoff(context,&create_asset_response).await.map_err(PollOperationError::CreateAssetResponseGetAsset)
|
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
|
//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;
|
let cookie_context=&cookie_context;
|
||||||
|
async move{(path,
|
||||||
async move{
|
async move{
|
||||||
let asset_response=asset_response_result.map_err(DownloadDecalError::PollOperation)?;
|
let asset_response=asset_response_result.map_err(DownloadDecalError::PollOperation)?;
|
||||||
let file=cookie_context.get_asset(rbx_asset::cookie::GetAssetRequest{
|
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))
|
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{
|
match download_decal_result{
|
||||||
Ok((file_name,asset_url))=>println!("{}={}",file_name,asset_url),
|
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;
|
}).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user