diff --git a/mediarepo-api/src/client_api/file.rs b/mediarepo-api/src/client_api/file.rs index 419289f..3ef6d4c 100644 --- a/mediarepo-api/src/client_api/file.rs +++ b/mediarepo-api/src/client_api/file.rs @@ -10,6 +10,7 @@ use async_trait::async_trait; use bromine::context::{PoolGuard, PooledContext}; use bromine::payload::BytePayload; use bromine::prelude::*; +use tokio::time::Duration; pub struct FileApi { ctx: PooledContext, @@ -43,12 +44,12 @@ impl FileApi { /// Returns all known files #[tracing::instrument(level = "debug", skip(self))] pub async fn all_files(&self) -> ApiResult> { - self.emit_and_get("all_files", ()).await + self.emit_and_get("all_files", (), Some(Duration::from_secs(30))).await } /// Returns a file by identifier pub async fn get_file(&self, id: FileIdentifier) -> ApiResult { - self.emit_and_get("get_file", id).await + self.emit_and_get("get_file", id, Some(Duration::from_secs(2))).await } /// Searches for a file by a list of tags @@ -64,6 +65,7 @@ impl FileApi { filters, sort_expression, }, + Some(Duration::from_secs(20)) ) .await } @@ -72,7 +74,7 @@ impl FileApi { #[tracing::instrument(level = "debug", skip(self))] pub async fn read_file(&self, id: FileIdentifier) -> ApiResult> { let payload: BytePayload = self - .emit_and_get("read_file", ReadFileRequest { id }) + .emit_and_get("read_file", ReadFileRequest { id }, Some(Duration::from_secs(10))) .await?; Ok(payload.into_inner()) @@ -84,7 +86,7 @@ impl FileApi { &self, id: FileIdentifier, ) -> ApiResult> { - self.emit_and_get("get_thumbnails", GetFileThumbnailsRequest { id }) + self.emit_and_get("get_thumbnails", GetFileThumbnailsRequest { id }, Some(Duration::from_secs(2))) .await } @@ -104,6 +106,7 @@ impl FileApi { min_size, max_size, }, + Some(Duration::from_secs(2)) ) .await?; let (metadata, bytes) = payload.into_inner(); @@ -118,7 +121,7 @@ impl FileApi { file_id: FileIdentifier, name: String, ) -> ApiResult { - self.emit_and_get("update_file_name", UpdateFileNameRequest { file_id, name }) + self.emit_and_get("update_file_name", UpdateFileNameRequest { file_id, name }, Some(Duration::from_secs(1))) .await } @@ -135,7 +138,7 @@ impl FileApi { BytePayload::new(bytes), ); - self.emit_and_get("add_file", payload).await + self.emit_and_get("add_file", payload, Some(Duration::from_secs(5))).await } /// Deletes all thumbnails of a file to regenerate them when requested diff --git a/mediarepo-api/src/client_api/mod.rs b/mediarepo-api/src/client_api/mod.rs index d6969a4..0bc1564 100644 --- a/mediarepo-api/src/client_api/mod.rs +++ b/mediarepo-api/src/client_api/mod.rs @@ -12,7 +12,7 @@ use crate::types::misc::{check_apis_compatible, get_api_version, InfoResponse}; use async_trait::async_trait; use bromine::ipc::stream_emitter::EmitMetadata; use bromine::prelude::*; -use std::time::Duration; +use tokio::time::Duration; #[async_trait] pub trait IPCApi { @@ -34,8 +34,13 @@ pub trait IPCApi { &self, event_name: &str, data: T, + timeout: Option, ) -> ApiResult { - let meta = self.emit(event_name, data).await?; + let mut meta = self.emit(event_name, data).await?; + + if let Some(timeout) = timeout { + meta = meta.with_timeout(timeout); + } let response = meta.await_reply(&self.ctx()).await?; Ok(response.payload()?) @@ -77,7 +82,7 @@ impl ApiClient { ) -> ApiResult { let ctx = IPCBuilder::::new() .address(address) - .timeout(Duration::from_secs(30)) + .timeout(Duration::from_secs(10)) .build_pooled_client(8) .await?; let client = Self::new(ctx); diff --git a/mediarepo-api/src/client_api/repo.rs b/mediarepo-api/src/client_api/repo.rs index 03a0812..45e234f 100644 --- a/mediarepo-api/src/client_api/repo.rs +++ b/mediarepo-api/src/client_api/repo.rs @@ -2,6 +2,7 @@ use crate::client_api::error::ApiResult; use crate::client_api::IPCApi; use crate::types::repo::FrontendState; use bromine::prelude::*; +use tokio::time::Duration; #[derive(Clone)] pub struct RepoApi { @@ -26,7 +27,7 @@ impl RepoApi { /// Returns the state of the frontend that is stored in the repo #[tracing::instrument(level = "debug", skip(self))] pub async fn get_frontend_state(&self) -> ApiResult { - let state = self.emit_and_get("frontend_state", ()).await?; + let state = self.emit_and_get("frontend_state", (), Some(Duration::from_secs(5))).await?; Ok(state) } diff --git a/mediarepo-api/src/client_api/tag.rs b/mediarepo-api/src/client_api/tag.rs index 6541b6a..ec030da 100644 --- a/mediarepo-api/src/client_api/tag.rs +++ b/mediarepo-api/src/client_api/tag.rs @@ -1,3 +1,4 @@ +use std::time::Duration; use crate::client_api::error::ApiResult; use crate::client_api::IPCApi; use crate::types::files::{GetFileTagsRequest, GetFilesTagsRequest}; @@ -38,27 +39,27 @@ impl TagApi { /// Returns a list of all tags stored in the repo #[tracing::instrument(level = "debug", skip(self))] pub async fn get_all_tags(&self) -> ApiResult> { - self.emit_and_get("all_tags", ()).await + self.emit_and_get("all_tags", (), Some(Duration::from_secs(2))).await } /// Returns a list of all tags for a file #[tracing::instrument(level = "debug", skip(self))] pub async fn get_tags_for_file(&self, id: FileIdentifier) -> ApiResult> { - self.emit_and_get("tags_for_file", GetFileTagsRequest { id }) + self.emit_and_get("tags_for_file", GetFileTagsRequest { id }, Some(Duration::from_secs(1))) .await } /// Returns a list of all tags that are assigned to the list of files #[tracing::instrument(level = "debug", skip_all)] pub async fn get_tags_for_files(&self, hashes: Vec) -> ApiResult> { - self.emit_and_get("tags_for_files", GetFilesTagsRequest { hashes }) + self.emit_and_get("tags_for_files", GetFilesTagsRequest { hashes }, Some(Duration::from_secs(10))) .await } /// Creates a new tag and returns the created tag object #[tracing::instrument(level = "debug", skip(self))] pub async fn create_tags(&self, tags: Vec) -> ApiResult> { - self.emit_and_get("create_tags", tags).await + self.emit_and_get("create_tags", tags, Some(Duration::from_secs(10))).await } /// Changes the tags of a file @@ -76,6 +77,7 @@ impl TagApi { added_tags, removed_tags, }, + Some(Duration::from_secs(10)) ) .await }