-
Notifications
You must be signed in to change notification settings - Fork 68
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
Reason simplification #858
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ use anyhow::Result; | |
use derive_more::Display; | ||
|
||
use crate::market::termination_reason::BreakReason; | ||
use ya_client::model::market::Reason; | ||
|
||
/// Response for requestor proposals. | ||
#[derive(Debug, Display)] | ||
|
@@ -21,7 +22,7 @@ pub enum ProposalResponse { | |
"reason.as_ref().map(|r| format!(\" (reason: {})\", r)).unwrap_or(\"\".into())" | ||
)] | ||
RejectProposal { | ||
reason: Option<String>, | ||
reason: Option<Reason>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}, | ||
///< Don't send any message to requestor. Could be useful to wait for other offers. | ||
IgnoreProposal, | ||
|
@@ -37,7 +38,7 @@ pub enum AgreementResponse { | |
"reason.as_ref().map(|r| format!(\" (reason: {})\", r)).unwrap_or(\"\".into())" | ||
)] | ||
RejectAgreement { | ||
reason: Option<String>, | ||
reason: Option<Reason>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}, | ||
} | ||
|
||
|
@@ -81,7 +82,7 @@ mod tests { | |
}; | ||
let no_reason = ProposalResponse::RejectProposal { reason: None }; | ||
|
||
assert_eq!(reason.to_string(), "RejectProposal (reason: zima)"); | ||
assert_eq!(reason.to_string(), "RejectProposal (reason: 'zima')"); | ||
assert_eq!(no_reason.to_string(), "RejectProposal"); | ||
} | ||
|
||
|
@@ -92,7 +93,7 @@ mod tests { | |
}; | ||
let no_reason = AgreementResponse::RejectAgreement { reason: None }; | ||
|
||
assert_eq!(reason.to_string(), "RejectAgreement (reason: lato)"); | ||
assert_eq!(reason.to_string(), "RejectAgreement (reason: 'lato')"); | ||
assert_eq!(no_reason.to_string(), "RejectAgreement"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ use std::time::Duration; | |
use strum::EnumMessage; | ||
use strum_macros::*; | ||
|
||
use ya_client::model::market::Reason; | ||
|
||
#[derive(Display, EnumMessage, Debug, Clone, PartialEq)] | ||
#[non_exhaustive] | ||
pub enum BreakReason { | ||
|
@@ -21,7 +23,7 @@ pub enum BreakReason { | |
NoActivity(Duration), | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] | ||
pub struct GolemReason { | ||
#[serde(rename = "message")] | ||
pub message: String, | ||
|
@@ -47,4 +49,26 @@ impl GolemReason { | |
extra: HashMap::new(), | ||
} | ||
} | ||
|
||
pub fn to_client(&self) -> Option<Reason> { | ||
match Reason::from_value(self) { | ||
Ok(r) => Some(r), | ||
Err(e) => { | ||
log::warn!("{}", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This message could be bettter |
||
None | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_try_convert_self() { | ||
let g = GolemReason::success(); | ||
let g1: GolemReason = g.to_client().unwrap().to_value().unwrap(); | ||
assert_eq!(g, g1) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to remember to clean this