mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 19:31:35 +00:00
Differentiate missing files in old vs new store for migration
This commit is contained in:
parent
55777c7b58
commit
75be876d3c
1 changed files with 24 additions and 7 deletions
29
src/lib.rs
29
src/lib.rs
|
@ -1672,13 +1672,21 @@ where
|
||||||
loop {
|
loop {
|
||||||
match do_migrate_file(from, to, identifier).await {
|
match do_migrate_file(from, to, identifier).await {
|
||||||
Ok(identifier) => return Ok(identifier),
|
Ok(identifier) => return Ok(identifier),
|
||||||
Err(e) if e.is_not_found() && skip_missing_files => return Err(e),
|
Err(MigrateError::From(e)) if e.is_not_found() && skip_missing_files => return Err(e),
|
||||||
Err(e) => {
|
Err(migrate_error) => {
|
||||||
failure_count += 1;
|
failure_count += 1;
|
||||||
|
|
||||||
if failure_count > 10 {
|
if failure_count > 10 {
|
||||||
tracing::error!("Error migrating file, not retrying");
|
match migrate_error {
|
||||||
|
MigrateError::From(e) => {
|
||||||
|
tracing::error!("Error migrating file FROM old store, not retrying");
|
||||||
return Err(e);
|
return Err(e);
|
||||||
|
}
|
||||||
|
MigrateError::To(e) => {
|
||||||
|
tracing::error!("Error migrating file TO new store, not retrying");
|
||||||
|
return Err(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
tracing::warn!("Failed moving file. Retrying +{failure_count}");
|
tracing::warn!("Failed moving file. Retrying +{failure_count}");
|
||||||
}
|
}
|
||||||
|
@ -1689,18 +1697,27 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum MigrateError {
|
||||||
|
From(crate::store::StoreError),
|
||||||
|
To(crate::store::StoreError),
|
||||||
|
}
|
||||||
|
|
||||||
async fn do_migrate_file<S1, S2>(
|
async fn do_migrate_file<S1, S2>(
|
||||||
from: &S1,
|
from: &S1,
|
||||||
to: &S2,
|
to: &S2,
|
||||||
identifier: &S1::Identifier,
|
identifier: &S1::Identifier,
|
||||||
) -> Result<S2::Identifier, crate::store::StoreError>
|
) -> Result<S2::Identifier, MigrateError>
|
||||||
where
|
where
|
||||||
S1: Store,
|
S1: Store,
|
||||||
S2: Store,
|
S2: Store,
|
||||||
{
|
{
|
||||||
let stream = from.to_stream(identifier, None, None).await?;
|
let stream = from
|
||||||
|
.to_stream(identifier, None, None)
|
||||||
|
.await
|
||||||
|
.map_err(MigrateError::From)?;
|
||||||
|
|
||||||
let new_identifier = to.save_stream(stream).await?;
|
let new_identifier = to.save_stream(stream).await.map_err(MigrateError::To)?;
|
||||||
|
|
||||||
Ok(new_identifier)
|
Ok(new_identifier)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue