mirror of
https://git.asonix.dog/asonix/pict-rs.git
synced 2024-11-24 18:41:06 +00:00
Retry in-process, and rate-limit self
This commit is contained in:
parent
ad2c5e5027
commit
28f7a139a0
3 changed files with 33 additions and 3 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1591,7 +1591,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pict-rs"
|
||||
version = "0.4.0-beta.12"
|
||||
version = "0.4.0-beta.13"
|
||||
dependencies = [
|
||||
"actix-form-data",
|
||||
"actix-rt",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "pict-rs"
|
||||
description = "A simple image hosting service"
|
||||
version = "0.4.0-beta.12"
|
||||
version = "0.4.0-beta.13"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
license = "AGPL-3.0"
|
||||
readme = "README.md"
|
||||
|
|
32
src/lib.rs
32
src/lib.rs
|
@ -42,7 +42,7 @@ use std::{
|
|||
path::Path,
|
||||
path::PathBuf,
|
||||
sync::atomic::{AtomicU64, Ordering},
|
||||
time::{Duration, SystemTime},
|
||||
time::{Duration, Instant, SystemTime},
|
||||
};
|
||||
use tokio::sync::Semaphore;
|
||||
use tracing_actix_web::TracingLogger;
|
||||
|
@ -1315,6 +1315,28 @@ const STORE_MIGRATION_MOTION: &str = "store-migration-motion";
|
|||
const STORE_MIGRATION_VARIANT: &str = "store-migration-variant";
|
||||
|
||||
async fn migrate_store<R, S1, S2>(repo: &R, from: S1, to: S2) -> Result<(), Error>
|
||||
where
|
||||
S1: Store + Clone,
|
||||
S2: Store + Clone,
|
||||
R: IdentifierRepo + HashRepo + SettingsRepo,
|
||||
{
|
||||
let mut failure_count = 0;
|
||||
|
||||
while let Err(e) = do_migrate_store(repo, from.clone(), to.clone()).await {
|
||||
tracing::error!("Failed with {}", e.to_string());
|
||||
failure_count += 1;
|
||||
|
||||
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||
|
||||
if failure_count >= 50 {
|
||||
tracing::error!("Exceeded 50 errors");
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
async fn do_migrate_store<R, S1, S2>(repo: &R, from: S1, to: S2) -> Result<(), Error>
|
||||
where
|
||||
S1: Store,
|
||||
S2: Store,
|
||||
|
@ -1395,10 +1417,18 @@ where
|
|||
S1: Store,
|
||||
S2: Store,
|
||||
{
|
||||
const CONST_TIME: Duration = Duration::from_millis(250);
|
||||
|
||||
let start = Instant::now();
|
||||
let stream = from.to_stream(identifier, None, None).await?;
|
||||
|
||||
let new_identifier = to.save_stream(stream).await?;
|
||||
|
||||
let elapsed = start.elapsed();
|
||||
if elapsed < CONST_TIME {
|
||||
tokio::time::sleep(CONST_TIME - elapsed).await;
|
||||
}
|
||||
|
||||
Ok(new_identifier)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue