fix: Make sigstore driver more resilient to network errors
This commit is contained in:
parent
0c52cf6a54
commit
486961f3d3
2 changed files with 34 additions and 25 deletions
|
|
@ -21,7 +21,7 @@ use blake2::{
|
|||
};
|
||||
use chrono::Local;
|
||||
use format_serde_error::SerdeError;
|
||||
use log::trace;
|
||||
use log::{trace, warn};
|
||||
use miette::{miette, Context, IntoDiagnostic, Result};
|
||||
|
||||
use crate::constants::CONTAINER_FILE;
|
||||
|
|
@ -72,16 +72,17 @@ pub fn serde_yaml_err(contents: &str) -> impl Fn(serde_yaml::Error) -> SerdeErro
|
|||
///
|
||||
/// # Errors
|
||||
/// Will error when retries have been expended.
|
||||
pub fn retry<V, F>(mut retries: u8, delay_secs: u64, f: F) -> miette::Result<V>
|
||||
pub fn retry<V, F>(mut retries: u8, delay_secs: u64, mut f: F) -> miette::Result<V>
|
||||
where
|
||||
F: Fn() -> miette::Result<V>,
|
||||
F: FnMut() -> miette::Result<V>,
|
||||
{
|
||||
loop {
|
||||
match f() {
|
||||
Ok(v) => return Ok(v),
|
||||
Err(e) if retries == 0 => return Err(e),
|
||||
_ => {
|
||||
Err(e) => {
|
||||
retries -= 1;
|
||||
warn!("Failed operation, will retry {retries} more time(s). Error:\n{e:?}");
|
||||
thread::sleep(Duration::from_secs(delay_secs));
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue