add timeouts to http requests
All checks were successful
tests / fmt (push) Successful in 2m5s
tests / clippy (push) Successful in 2m29s
tests / pre-commit (push) Successful in 2m33s
tests / test (push) Successful in 2m44s
tests / build (push) Successful in 2m54s
deploy / release-image (push) Successful in 9m8s

This commit is contained in:
2024-07-04 21:31:40 +02:00
parent dfd0f9c8c8
commit 1e523502eb
3 changed files with 14 additions and 3 deletions

View File

@@ -341,13 +341,17 @@ pub(crate) async fn play(
.or(yttrack.url.clone())
.ok_or("Could not find url")?;
let mut src = YoutubeDl::new(reqwest::Client::new(), url.clone());
let mut src = YoutubeDl::new(state.client.clone(), url.clone());
let track: Track = src.clone().into();
if let Ok(metadata) = src.aux_metadata().await {
debug!("metadata: {:?}", metadata);
persistence(&interaction, yttrack, Arc::clone(&state)).await?;
persistence(&interaction, yttrack, Arc::clone(&state))
.await
.unwrap_or_else(|e| {
tracing::error!("could not persist track: {:?}", e);
});
tracks_added.push(TrackType {
url: url.clone(),

View File

@@ -16,7 +16,7 @@ use futures::StreamExt;
use signal::signal_handler;
use songbird::{shards::TwilightMap, Songbird};
use state::StateRef;
use std::{env, error::Error, str::FromStr, sync::Arc};
use std::{env, error::Error, str::FromStr, sync::Arc, time::Duration};
use tokio::select;
use tracing::{debug, info};
use twilight_cache_inmemory::InMemoryCache;
@@ -82,6 +82,11 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
);
let songbird = Songbird::twilight(Arc::new(senders), user_id);
let cache = InMemoryCache::new();
let client = reqwest::ClientBuilder::new()
.connect_timeout(Duration::from_secs(10))
.timeout(Duration::from_secs(3600))
.build()
.expect("could not build http client");
(
shards,
@@ -92,6 +97,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
standby: Standby::new(),
guild_settings: Default::default(),
pool,
client,
}),
)
};

View File

@@ -33,4 +33,5 @@ pub(crate) struct StateRef {
pub(crate) standby: Standby,
pub(crate) guild_settings: DashMap<Id<GuildMarker>, Settings>,
pub(crate) pool: sqlx::SqlitePool,
pub(crate) client: reqwest::Client,
}