Skip to content

Commit e67ae5e

Browse files
committed
use Duration as type in configuration for timeout
1 parent 7bd57a4 commit e67ae5e

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/config.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use crate::{cdn::CdnKind, storage::StorageKind};
22
use anyhow::{anyhow, bail, Context, Result};
3-
use std::env::VarError;
4-
use std::error::Error;
5-
use std::path::PathBuf;
6-
use std::str::FromStr;
3+
use std::{env::VarError, error::Error, path::PathBuf, str::FromStr, time::Duration};
74
use tracing::trace;
85

96
#[derive(Debug)]
@@ -42,7 +39,7 @@ pub struct Config {
4239
pub(crate) gitlab_accesstoken: Option<String>,
4340

4441
// request timeout in seconds
45-
pub(crate) request_timeout: Option<u64>,
42+
pub(crate) request_timeout: Option<Duration>,
4643
pub(crate) report_request_timeouts: bool,
4744

4845
// Max size of the files served by the docs.rs frontend
@@ -161,7 +158,7 @@ impl Config {
161158
max_parse_memory: env("DOCSRS_MAX_PARSE_MEMORY", 5 * 1024 * 1024)?,
162159
registry_gc_interval: env("DOCSRS_REGISTRY_GC_INTERVAL", 60 * 60)?,
163160
render_threads: env("DOCSRS_RENDER_THREADS", num_cpus::get())?,
164-
request_timeout: maybe_env("DOCSRS_REQUEST_TIMEOUT")?,
161+
request_timeout: maybe_env::<u64>("DOCSRS_REQUEST_TIMEOUT")?.map(Duration::from_secs),
165162
report_request_timeouts: env("DOCSRS_REPORT_REQUEST_TIMEOUTS", false)?,
166163

167164
random_crate_search_view_size: env("DOCSRS_RANDOM_CRATE_SEARCH_VIEW_SIZE", 500)?,

src/web/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ use postgres::Client;
4747
use semver::{Version, VersionReq};
4848
use serde::Serialize;
4949
use std::borrow::Borrow;
50-
use std::time::Duration;
5150
use std::{borrow::Cow, net::SocketAddr, sync::Arc};
5251
use tower::ServiceBuilder;
5352
use tower_http::{timeout::TimeoutLayer, trace::TraceLayer};
@@ -281,9 +280,7 @@ pub(crate) fn build_axum_app(
281280
.report_request_timeouts
282281
.then_some(middleware::from_fn(log_timeouts_to_sentry)),
283282
))
284-
.layer(option_layer(config.request_timeout.map(|timeout| {
285-
TimeoutLayer::new(Duration::from_secs(timeout))
286-
})))
283+
.layer(option_layer(config.request_timeout.map(TimeoutLayer::new)))
287284
.layer(Extension(context.pool()?))
288285
.layer(Extension(context.build_queue()?))
289286
.layer(Extension(context.metrics()?))

0 commit comments

Comments
 (0)