diff options
author | Christoph Prokop <christoph.prokop@atos.net> | 2021-04-13 10:49:54 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-04-13 11:28:58 +0200 |
commit | 441ae36017058ecbf66951c26176f24fb809471d (patch) | |
tree | 4d606c6f4ccc4c85fd451c91f132da0ee7cfd224 | |
parent | b1d9a89c93eb500bfd14f236830b8bdc73f2ee74 (diff) |
Add configurable timeout
This patch adds a configurable timeout value (default 10 seconds)
in the Endpoint struct.
This way we get an error if the connection to the endpoint is stalled.
Signed-off-by: Christoph Prokop <christoph.prokop@atos.net>
Pair-programmed-with: Matthias Beyer <matthias.beyer@atos.net>
Suggested-by: Matthias Beyer <matthias.beyer@atos.net>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | config.toml | 2 | ||||
-rw-r--r-- | src/config/endpoint_config.rs | 4 | ||||
-rw-r--r-- | src/endpoint/configured.rs | 9 |
3 files changed, 13 insertions, 2 deletions
diff --git a/config.toml b/config.toml index 46fc7cc..79f341a 100644 --- a/config.toml +++ b/config.toml @@ -173,6 +173,8 @@ verify_images_present = true [docker.endpoints.testhostname] uri = "http://0.0.0.0:8095" # the URI of the endpoint. Either http or socket path endpoint_type = "http" # either "http" or "socket" +# optional timeout for connecting to endpoint in seconds, default: 10 seconds +# timeout = 5 # maximum number of jobs running on this endpoint. # Set this to a reasonable high number to be able to run a lot of small jobs. diff --git a/src/config/endpoint_config.rs b/src/config/endpoint_config.rs index 69405dc..05d420f 100644 --- a/src/config/endpoint_config.rs +++ b/src/config/endpoint_config.rs @@ -50,6 +50,10 @@ pub struct Endpoint { #[getset(get = "pub")] network_mode: Option<String>, + + /// Duration length of timeout for connecting endpoint + #[getset(get = "pub")] + timeout: Option<u64>, } /// The type of an endpoint diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index f850ff6..8fdec64 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -84,8 +84,13 @@ impl Endpoint { Endpoint::check_api_version_compat(epc.required_docker_api_versions().as_ref(), &ep); let imgs_avail = Endpoint::check_images_available(epc.required_images().as_ref(), &ep); - let (versions_compat, api_versions_compat, imgs_avail) = - tokio::join!(versions_compat, api_versions_compat, imgs_avail); + let (versions_compat, api_versions_compat, imgs_avail) = { + let timeout = std::time::Duration::from_secs(epc.endpoint().timeout().unwrap_or(10)); + let versions_compat = tokio::time::timeout(timeout, versions_compat); + let api_versions_compat = tokio::time::timeout(timeout, api_versions_compat); + let imgs_avail = tokio::time::timeout(timeout, imgs_avail); + tokio::join!(versions_compat, api_versions_compat, imgs_avail) + }; let _ = versions_compat.with_context(|| { anyhow!( |