Skip to content

Commit

Permalink
OpenAPItor has configurable request timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchalmers committed Aug 8, 2023
1 parent a1c1178 commit def6266
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
17 changes: 8 additions & 9 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ kittycad: target/debug/openapitor
-d "A fully generated & opinionated API client for the KittyCAD API." \
--spec-url "https://api.kittycad.io" \
--base-url "https://api.kittycad.io" \
--request-timeout-seconds 600 \
--repo-name "KittyCAD/kittycad.rs" $(EXTRA_ARGS)
mv -f $(CURDIR)/kittycad/kittycad.rs.patch.json $(CURDIR)

Expand Down
2 changes: 1 addition & 1 deletion kittycad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl Client {
let client_http1 = reqwest::Client::builder()
// For file conversions we need this to be long.
.user_agent(APP_USER_AGENT)
.timeout(std::time::Duration::from_secs(60))
.timeout(std::time::Duration::from_secs(600))
.connect_timeout(std::time::Duration::from_secs(60))
.http1_only()
.build();
Expand Down
19 changes: 15 additions & 4 deletions openapitor/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ pub fn generate_client(opts: &crate::Opts) -> String {
"USER_CONSENT_ENDPOINT",
opts.user_consent_endpoint.as_ref().unwrap().as_ref(),
)
.replace(
"TIMEOUT_NUM_SECONDS",
&opts.request_timeout_seconds.to_string(),
)
.replace("BASE_URL", opts.base_url.to_string().trim_end_matches('/'));
}

if opts.basic_auth {
return CLIENT_FUNCTIONS_BASIC_AUTH
.replace(
"TIMEOUT_NUM_SECONDS",
&opts.request_timeout_seconds.to_string(),
)

Check warning on line 33 in openapitor/src/client.rs

View check run for this annotation

Codecov / codecov/patch

openapitor/src/client.rs#L30-L33

Added lines #L30 - L33 were not covered by tests
.replace(
"ENV_VARIABLE_PREFIX",
&crate::template::get_env_variable_prefix(&opts.name),
Expand All @@ -31,6 +39,10 @@ pub fn generate_client(opts: &crate::Opts) -> String {
}

CLIENT_FUNCTIONS_TOKEN
.replace(
"TIMEOUT_NUM_SECONDS",
&opts.request_timeout_seconds.to_string(),
)
.replace(
"ENV_VARIABLE_PREFIX",
&crate::template::get_env_variable_prefix(&opts.name),
Expand Down Expand Up @@ -74,8 +86,7 @@ impl Client {
reqwest_retry::policies::ExponentialBackoff::builder().build_with_max_retries(3);
let client = reqwest::Client::builder()
.user_agent(APP_USER_AGENT)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.timeout(std::time::Duration::from_secs(TIMEOUT_NUM_SECONDS))
.connect_timeout(std::time::Duration::from_secs(60))
.build();
match client {
Expand Down Expand Up @@ -201,13 +212,13 @@ impl Client {
let client = reqwest::Client::builder()
.user_agent(APP_USER_AGENT)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.timeout(std::time::Duration::from_secs(TIMEOUT_NUM_SECONDS))
.connect_timeout(std::time::Duration::from_secs(60))
.build();
let client_http1 = reqwest::Client::builder()
// For file conversions we need this to be long.
.user_agent(APP_USER_AGENT)
.timeout(std::time::Duration::from_secs(60))
.timeout(std::time::Duration::from_secs(TIMEOUT_NUM_SECONDS))
.connect_timeout(std::time::Duration::from_secs(60))
.http1_only()
.build();
Expand Down
5 changes: 5 additions & 0 deletions openapitor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ pub struct Opts {
/// Use basic auth for authentication instead of bearer tokens
#[arg(long)]
pub basic_auth: bool,

/// Default timeout on the client
#[arg(long)]
pub request_timeout_seconds: u64,

Check warning on line 464 in openapitor/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

openapitor/src/lib.rs#L464

Added line #L464 was not covered by tests
}

impl Opts {
Expand Down Expand Up @@ -523,6 +527,7 @@ impl Default for Opts {
user_consent_endpoint: Default::default(),
date_time_format: Default::default(),
basic_auth: Default::default(),
request_timeout_seconds: 60,
}
}
}
Expand Down

0 comments on commit def6266

Please sign in to comment.