mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 19:31:35 +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")]
|
#[error("Client took too long to send request")]
|
||||||
AggregateTimeout,
|
AggregateTimeout,
|
||||||
|
|
||||||
|
#[error("Timed out while waiting for media processing")]
|
||||||
|
ProcessTimeout,
|
||||||
|
|
||||||
#[error("Failed external validation")]
|
#[error("Failed external validation")]
|
||||||
FailedExternalValidation,
|
FailedExternalValidation,
|
||||||
}
|
}
|
||||||
|
@ -187,6 +190,7 @@ impl UploadError {
|
||||||
Self::Range => ErrorCode::RANGE_NOT_SATISFIABLE,
|
Self::Range => ErrorCode::RANGE_NOT_SATISFIABLE,
|
||||||
Self::Limit(_) => ErrorCode::VALIDATE_FILE_SIZE,
|
Self::Limit(_) => ErrorCode::VALIDATE_FILE_SIZE,
|
||||||
Self::Timeout(_) | Self::AggregateTimeout => ErrorCode::STREAM_TOO_SLOW,
|
Self::Timeout(_) | Self::AggregateTimeout => ErrorCode::STREAM_TOO_SLOW,
|
||||||
|
Self::ProcessTimeout => ErrorCode::COMMAND_TIMEOUT,
|
||||||
Self::FailedExternalValidation => ErrorCode::FAILED_EXTERNAL_VALIDATION,
|
Self::FailedExternalValidation => ErrorCode::FAILED_EXTERNAL_VALIDATION,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,17 @@ use crate::{
|
||||||
details::Details,
|
details::Details,
|
||||||
error::{Error, UploadError},
|
error::{Error, UploadError},
|
||||||
formats::{ImageFormat, InputProcessableFormat, InternalVideoFormat, ProcessableFormat},
|
formats::{ImageFormat, InputProcessableFormat, InternalVideoFormat, ProcessableFormat},
|
||||||
|
future::{WithMetrics, WithTimeout},
|
||||||
repo::{ArcRepo, Hash, VariantAlreadyExists},
|
repo::{ArcRepo, Hash, VariantAlreadyExists},
|
||||||
store::Store,
|
store::Store,
|
||||||
tmp_file::TmpDir,
|
tmp_file::TmpDir,
|
||||||
};
|
};
|
||||||
use actix_web::web::Bytes;
|
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 tokio::io::AsyncReadExt;
|
||||||
use tracing::Instrument;
|
use tracing::Instrument;
|
||||||
|
|
||||||
|
@ -79,7 +84,10 @@ pub(crate) async fn generate<S: Store + 'static>(
|
||||||
|
|
||||||
let (details, bytes) = process_map
|
let (details, bytes) = process_map
|
||||||
.process(hash, thumbnail_path, process_fut)
|
.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))
|
Ok((details, bytes))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue