mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-11-20 11:21:14 +00:00
Add timeout and metrics to media processing
This commit is contained in:
parent
a21fd1e135
commit
961de20a00
2 changed files with 14 additions and 2 deletions
|
@ -153,6 +153,9 @@ pub(crate) enum UploadError {
|
|||
#[error("Client took too long to send request")]
|
||||
AggregateTimeout,
|
||||
|
||||
#[error("Timed out while waiting for media processing")]
|
||||
ProcessTimeout,
|
||||
|
||||
#[error("Failed external validation")]
|
||||
FailedExternalValidation,
|
||||
}
|
||||
|
@ -187,6 +190,7 @@ impl UploadError {
|
|||
Self::Range => ErrorCode::RANGE_NOT_SATISFIABLE,
|
||||
Self::Limit(_) => ErrorCode::VALIDATE_FILE_SIZE,
|
||||
Self::Timeout(_) | Self::AggregateTimeout => ErrorCode::STREAM_TOO_SLOW,
|
||||
Self::ProcessTimeout => ErrorCode::COMMAND_TIMEOUT,
|
||||
Self::FailedExternalValidation => ErrorCode::FAILED_EXTERNAL_VALIDATION,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,17 @@ use crate::{
|
|||
details::Details,
|
||||
error::{Error, UploadError},
|
||||
formats::{ImageFormat, InputProcessableFormat, InternalVideoFormat, ProcessableFormat},
|
||||
future::{WithMetrics, WithTimeout},
|
||||
repo::{ArcRepo, Hash, VariantAlreadyExists},
|
||||
store::Store,
|
||||
tmp_file::TmpDir,
|
||||
};
|
||||
use actix_web::web::Bytes;
|
||||
use std::{path::PathBuf, sync::Arc, time::Instant};
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tracing::Instrument;
|
||||
|
||||
|
@ -79,7 +84,10 @@ pub(crate) async fn generate<S: Store + 'static>(
|
|||
|
||||
let (details, bytes) = process_map
|
||||
.process(hash, thumbnail_path, process_fut)
|
||||
.await?;
|
||||
.with_timeout(Duration::from_secs(config.media.process_timeout * 4))
|
||||
.with_metrics("pict-rs.generate.process")
|
||||
.await
|
||||
.map_err(|_| UploadError::ProcessTimeout)??;
|
||||
|
||||
Ok((details, bytes))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue