Skip to content

Commit

Permalink
Merge pull request #1334 from Barsik-sus/willbe-publish-retry
Browse files Browse the repository at this point in the history
READY: (willbe): Provided new functionality to retry publication attempts
  • Loading branch information
Wandalen authored May 14, 2024
2 parents 9c9260f + 5bf6c76 commit 5f52ee8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions module/move/willbe/src/entity/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ mod private
{
path : crate_dir.as_ref().into(),
temp_path : self.base_temp_dir.clone(),
retry_count : 2,
dry : self.dry,
};

Expand Down
31 changes: 26 additions & 5 deletions module/move/willbe/src/tool/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod private

use std::path::PathBuf;
use error_tools::err;
use error_tools::for_app::format_err;
use former::Former;
use process_tools::process::*;
use wtools::error::Result;
Expand Down Expand Up @@ -92,6 +93,8 @@ mod private
{
pub( crate ) path : PathBuf,
pub( crate ) temp_path : Option< PathBuf >,
#[ former( default = 0usize ) ]
pub( crate ) retry_count : usize,
pub( crate ) dry : bool,
}

Expand Down Expand Up @@ -140,11 +143,29 @@ mod private
}
else
{
Run::former()
.bin_path( program )
.args( arguments.into_iter().map( OsString::from ).collect::< Vec< _ > >() )
.current_path( args.path )
.run().map_err( | report | err!( report.to_string() ) )
let mut results = Vec::with_capacity( args.retry_count + 1 );
let run_args = arguments.into_iter().map( OsString::from ).collect::< Vec< _ > >();
for _ in 0 .. args.retry_count + 1
{
let result = Run::former()
.bin_path( program )
.args( run_args.clone() )
.current_path( &args.path )
.run();
match result
{
Ok( report ) => return Ok( report ),
Err( e ) => results.push( e ),
}
}
if args.retry_count > 0
{
Err( format_err!( "It took {} attempts, but still failed. Here are the errors:\n{}", args.retry_count + 1, results.into_iter().map( | r | format!( "- {r}" ) ).collect::< Vec< _ > >().join( "\n" ) ) )
}
else
{
Err( results.remove( 0 ) ).map_err( | report | err!( report.to_string() ) )
}
}
}
}
Expand Down

0 comments on commit 5f52ee8

Please sign in to comment.