Skip to content

Commit

Permalink
implement suspension handling
Browse files Browse the repository at this point in the history
we wrap the RestClient given to us during SDK
construction in another implementation that suspends
requests if a previous request received a TooManyRequests
or ServiceUnavailable response

Co-authored-by: jhm <17314077+jomapp@users.noreply.github.com>
  • Loading branch information
ganthern and jomapp committed Nov 21, 2024
1 parent 998c87c commit 9adefc3
Show file tree
Hide file tree
Showing 26 changed files with 498 additions and 52 deletions.
2 changes: 1 addition & 1 deletion buildSrc/RustGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function generateRustServiceDefinition(appName, appVersion, services) {
"use crate::ApiCallError;",
"use crate::entities::Entity;",
"use crate::services::{PostService, GetService, PutService, DeleteService, Service, Executor, ExtraServiceParams};",
"use crate::rest_client::HttpMethod;",
"use crate::bindings::rest_client::HttpMethod;",
"use crate::services::hidden::Nothing;",
])
const code = services
Expand Down
6 changes: 3 additions & 3 deletions tuta-sdk/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tuta-sdk/rust/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ simple_logger = "5.0.0"
uniffi = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "13a1c559cb3708eeca40dcf95dc8b3ccccf3b88c" }
num_enum = "0.7.3"
lz4_flex = { version = "0.11.3", default-features = false, features = ["safe-encode", "safe-decode", "std"] }
tokio = { version = "1.41.1", features = ["rt", "rt-multi-thread", "macros"] }

# only used for the native rest client
hyper = { version = "1.4.1", features = ["client"], optional = true }
Expand Down Expand Up @@ -65,7 +66,6 @@ tuta-sdk = { path = ".", features = ["net", "testing"] }
mockall = { version = "0.13.0" }
mockall_double = { version = "0.3.1" }
rand = { version = "0.8.5" }
tokio = { version = "1.38.0", features = ["rt", "rt-multi-thread", "macros"] }

[lib]
crate-type = ["cdylib", "staticlib", "lib"]
Expand Down
5 changes: 3 additions & 2 deletions tuta-sdk/rust/sdk/examples/http_request.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use tutasdk::bindings::rest_client::RestResponse;
use tutasdk::bindings::rest_client::{HttpMethod, RestClient, RestClientOptions};
use tutasdk::net::native_rest_client::NativeRestClient;
use tutasdk::rest_client::RestResponse;
use tutasdk::rest_client::{HttpMethod, RestClient, RestClientOptions};

#[tokio::main]
async fn main() {
Expand All @@ -14,6 +14,7 @@ async fn main() {
RestClientOptions {
headers: Default::default(),
body: Default::default(),
suspension_behavior: Default::default(),
},
)
.await;
Expand Down
4 changes: 4 additions & 0 deletions tuta-sdk/rust/sdk/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod rest_client;
pub mod suspendable_rest_client;

pub mod test_rest_client;
1 change: 1 addition & 0 deletions tuta-sdk/rust/sdk/src/bindings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
files that deal with the interface to the embedding application
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::bindings::suspendable_rest_client::SuspensionBehavior;
use std::collections::HashMap;
use thiserror::Error;

Expand All @@ -14,6 +15,7 @@ pub enum HttpMethod {
pub struct RestClientOptions {
pub headers: HashMap<String, String>,
pub body: Option<Vec<u8>>,
pub suspension_behavior: Option<SuspensionBehavior>,
}

/// An error thrown by the `RestClient` (the injected HTTP client Kotlin/Swift/JavaScript)
Expand All @@ -31,6 +33,8 @@ pub enum RestClientError {
InvalidResponse,
#[error("failed tls setup")]
FailedTlsSetup,
#[error("suspended")]
Suspended,
}

/// Provides a Rust SDK level interface for performing REST requests
Expand Down
Loading

0 comments on commit 9adefc3

Please sign in to comment.