Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zincati: add completion timeout to HTTP requests #226

Merged
merged 2 commits into from Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/cincinnati/client.rs
Expand Up @@ -15,6 +15,10 @@ use reqwest::r#async as asynchro;
use reqwest::Method;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::time::Duration;

/// Default timeout for HTTP requests completion (30 minutes).
const DEFAULT_HTTP_COMPLETION_TIMEOUT: Duration = Duration::from_secs(30 * 60);

/// Cincinnati graph API path endpoint (v1).
static V1_GRAPH_PATH: &str = "v1/graph";
Expand Down Expand Up @@ -214,7 +218,10 @@ impl ClientBuilder {
pub fn build(self) -> Fallible<Client> {
let hclient = match self.hclient {
Some(client) => client,
None => asynchro::ClientBuilder::new().use_sys_proxy().build()?,
None => asynchro::ClientBuilder::new()
.use_sys_proxy()
.timeout(DEFAULT_HTTP_COMPLETION_TIMEOUT)
.build()?,
};
let query_params = match self.query_params {
Some(params) => params,
Expand Down
9 changes: 8 additions & 1 deletion src/fleet_lock/mod.rs
Expand Up @@ -12,10 +12,14 @@ use futures::prelude::*;
use reqwest::r#async as asynchro;
use reqwest::Method;
use serde::{Deserialize, Serialize};
use std::time::Duration;

#[cfg(test)]
mod mock_tests;

/// Default timeout for HTTP requests completion (30 minutes).
const DEFAULT_HTTP_COMPLETION_TIMEOUT: Duration = Duration::from_secs(30 * 60);

/// FleetLock pre-reboot API path endpoint (v1).
static V1_PRE_REBOOT: &str = "v1/pre-reboot";

Expand Down Expand Up @@ -231,7 +235,10 @@ impl ClientBuilder {
pub fn build(self) -> Fallible<Client> {
let hclient = match self.hclient {
Some(client) => client,
None => asynchro::ClientBuilder::new().use_sys_proxy().build()?,
None => asynchro::ClientBuilder::new()
.use_sys_proxy()
.timeout(DEFAULT_HTTP_COMPLETION_TIMEOUT)
.build()?,
};

let api_base = reqwest::Url::parse(&self.api_base)
Expand Down