Skip to content

Retry timeout #596

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

Merged
merged 3 commits into from
Jan 8, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions Cargo.lock

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

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ csv = "1.0.2"
dotenv = "0.13"
failure = "0.1.3"
flate2 = "1"
futures = "0.1.13"
http = "0.1.10"
hyper = "0.12.8"
lazy_static = "1.0"
mime = "0.3.1"
minifier = { version = "0.0.20", features = ["html"] }
paste = "0.1.3"
petgraph = "0.4.11"
r2d2 = "0.8.2"
r2d2_sqlite = "0.19.0"
Expand All @@ -49,7 +47,6 @@ structopt-derive = "0.2"
tar = "0.4.0"
tempfile = "3.0.0"
tera = "0.11.7"
tokio = "0.1.11"
toml = "0.4.6"
url = "1.1"
walkdir = "2"
Expand Down
13 changes: 1 addition & 12 deletions src/agent/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use reqwest::header::AUTHORIZATION;
use reqwest::{Method, StatusCode};
use serde::de::DeserializeOwned;
use serde_json::json;
use std::error::Error as _;

#[derive(Debug, Fail)]
pub enum AgentApiError {
Expand Down Expand Up @@ -93,17 +92,7 @@ impl AgentApi {
let retry = if let Some(AgentApiError::ServerUnavailable) = err.downcast_ref() {
true
} else if let Some(err) = err.downcast_ref::<::reqwest::Error>() {
let reqwest_io = err
.source()
.map(|inner| inner.is::<::std::io::Error>())
.unwrap_or(false);
let hyper_io = err
.source()
.and_then(|inner| inner.downcast_ref::<::hyper::Error>())
.and_then(|inner| inner.source())
.map(|inner| inner.is::<::std::io::Error>())
.unwrap_or(false);
reqwest_io || hyper_io
err.is_timeout() || err.is_connect()
} else {
false
};
Expand Down
7 changes: 4 additions & 3 deletions src/experiments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ string_enum!(pub enum CapLints {

const SMALL_RANDOM_COUNT: u32 = 20;

#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
#[serde(try_from = "String", into = "String")]
pub enum CrateSelect {
Full,
Demo,
Expand All @@ -55,6 +56,8 @@ pub enum CrateSelect {
List(HashSet<String>),
}

from_into_string!(CrateSelect);

impl FromStr for CrateSelect {
type Err = failure::Error;

Expand Down Expand Up @@ -167,8 +170,6 @@ impl FromStr for DeferredCrateSelect {
}
}

impl_serde_from_parse!(CrateSelect, expecting = "A valid value of `CrateSelect`");

#[cfg_attr(test, derive(Debug, PartialEq, Eq))]
#[derive(Clone, Serialize, Deserialize)]
pub enum Assignee {
Expand Down
5 changes: 3 additions & 2 deletions src/results/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ macro_rules! test_result_enum {
with_reason { $($with_reason_name:ident($reason:ident) => $with_reason_repr:expr,)* }
without_reason { $($reasonless_name:ident => $reasonless_repr:expr,)* }
}) => {
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
#[serde(try_from = "String", into = "String")]
pub enum $name {
$($with_reason_name($reason),)*
$($reasonless_name,)*
Expand Down Expand Up @@ -301,7 +302,7 @@ test_result_enum!(pub enum TestResult {
}
});

impl_serde_from_parse!(TestResult, expecting = "a test result");
from_into_string!(TestResult);

#[cfg(test)]
mod tests {
Expand Down
45 changes: 12 additions & 33 deletions src/utils/macros.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
macro_rules! string_enum {
($vis:vis enum $name:ident { $($item:ident => $str:expr,)* }) => {
#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)]
#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, Serialize, Deserialize)]
#[serde(try_from = "String", into = "String")]
$vis enum $name {
$($item,)*
}
Expand Down Expand Up @@ -36,44 +37,22 @@ macro_rules! string_enum {
}
}

impl_serde_from_parse!($name, expecting="foo");
from_into_string!($name);
}
}

macro_rules! impl_serde_from_parse {
($for:ident, expecting=$expecting:expr) => {
paste::item! {
struct [<$for Visitor>];

impl<'de> ::serde::de::Visitor<'de> for [<$for Visitor>] {
type Value = $for;

fn expecting(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.write_str($expecting)
}

fn visit_str<E: ::serde::de::Error>(self, input: &str) -> Result<$for, E> {
use std::str::FromStr;
$for::from_str(input).map_err(E::custom)
}
}
}

impl<'de> ::serde::de::Deserialize<'de> for $for {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: ::serde::de::Deserializer<'de>,
{
deserializer.deserialize_str(paste::expr! { [<$for Visitor>] })
macro_rules! from_into_string {
($for:ident) => {
impl std::convert::TryFrom<String> for $for {
type Error = <$for as std::str::FromStr>::Err;
fn try_from(s: String) -> Result<Self, <$for as std::str::FromStr>::Err> {
s.parse()
}
}

impl ::serde::ser::Serialize for $for {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::ser::Serializer,
{
serializer.serialize_str(&self.to_string())
impl From<$for> for String {
fn from(s: $for) -> String {
s.to_string()
}
}
};
Expand Down
7 changes: 4 additions & 3 deletions src/utils/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::prelude::*;
use std::fmt;
use std::str::FromStr;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(try_from = "String", into = "String")]
pub enum Size {
Bytes(usize),
Kilobytes(usize),
Expand All @@ -11,6 +12,8 @@ pub enum Size {
Terabytes(usize),
}

from_into_string!(Size);

impl Size {
pub(crate) fn to_bytes(&self) -> usize {
match self {
Expand Down Expand Up @@ -61,8 +64,6 @@ impl FromStr for Size {
}
}

impl_serde_from_parse!(Size, expecting = "a size");

#[cfg(test)]
mod tests {
use super::Size;
Expand Down