Skip to content

Commit

Permalink
Merge pull request #775 from golemfactory/market/new-market-api-1.6.1
Browse files Browse the repository at this point in the history
Adapt to new Market Api 1.6.1
  • Loading branch information
tworec committed Nov 9, 2020
2 parents 7f8eb0c + ca3052b commit e0d0944
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ ya-sb-router = { path = "service-bus/router" }
ya-sb-util = { path = "service-bus/util" }

## CLIENT
ya-client = { git = "https://github.com/golemfactory/ya-client.git", rev = "2e745dbc2056c8064a62f80cf51c5d6fc03411cb"}
ya-client-model = { git = "https://github.com/golemfactory/ya-client.git", rev = "2e745dbc2056c8064a62f80cf51c5d6fc03411cb"}
ya-client = { git = "https://github.com/golemfactory/ya-client.git", rev = "ba89a542f39ba659dcacecfe64930ed7e1e465de"}
ya-client-model = { git = "https://github.com/golemfactory/ya-client.git", rev = "ba89a542f39ba659dcacecfe64930ed7e1e465de"}

## OTHERS
gftp = { path = "core/gftp" }
Expand Down
21 changes: 18 additions & 3 deletions agent/provider/src/market/mock_negotiator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,25 @@ impl Negotiator for LimitAgreementsNegotiator {
"Negotiator: Reject proposal [{:?}] due to expiration limits.",
demand.proposal_id
);
Ok(ProposalResponse::RejectProposal)
Ok(ProposalResponse::RejectProposal {
reason: Some(format!(
"proposal expired at: {} which is less than 5 min or more than 30 min from now",
expiration
)),
})
} else if self.has_free_slot() {
Ok(ProposalResponse::AcceptProposal)
} else {
log::info!(
"Negotiator: Reject proposal [{:?}] due to limit.",
demand.proposal_id
);
Ok(ProposalResponse::RejectProposal)
Ok(ProposalResponse::RejectProposal {
reason: Some(format!(
"available agreements limit: {} reached",
self.max_agreements
)),
})
}
}

Expand All @@ -109,7 +119,12 @@ impl Negotiator for LimitAgreementsNegotiator {
"Negotiator: Reject agreement proposal [{}] due to limit.",
agreement.agreement_id
);
Ok(AgreementResponse::RejectAgreement)
Ok(AgreementResponse::RejectAgreement {
reason: Some(format!(
"available agreements limit: {} reached",
self.max_agreements
)),
})
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions agent/provider/src/market/negotiator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ pub enum ProposalResponse {
offer: DemandOfferBase,
},
AcceptProposal,
RejectProposal,
#[display(fmt = "RejectProposal( reason: {:?})", reason)]
RejectProposal {
reason: Option<String>,
},
///< Don't send any message to requestor. Could be useful to wait for other offers.
IgnoreProposal,
}
Expand All @@ -26,7 +29,10 @@ pub enum ProposalResponse {
#[allow(dead_code)]
pub enum AgreementResponse {
ApproveAgreement,
RejectAgreement,
#[display(fmt = "RejectAgreement( reason: {:?})", reason)]
RejectAgreement {
reason: Option<String>,
},
}

/// Result of agreement execution.
Expand Down
16 changes: 11 additions & 5 deletions agent/provider/src/market/provider_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::Arc;

use ya_agreement_utils::{AgreementView, OfferDefinition};
use ya_client::market::MarketProviderApi;
use ya_client_model::market::{Agreement, DemandOfferBase, Proposal, ProviderEvent};
use ya_client_model::market::{Agreement, DemandOfferBase, Proposal, ProviderEvent, Reason};
use ya_utils_actix::{
actix_handler::ResultTypeGetter,
actix_signal::{SignalSlot, Subscribe},
Expand Down Expand Up @@ -303,8 +303,13 @@ async fn process_proposal(
.await?;
}
ProposalResponse::IgnoreProposal => log::info!("Ignoring proposal {:?}", proposal_id),
ProposalResponse::RejectProposal => {
api.reject_proposal(&subscription.id, proposal_id).await?;
ProposalResponse::RejectProposal { reason } => {
api.reject_proposal_with_reason(
&subscription.id,
proposal_id,
reason.map(|r| Reason::new(r)),
)
.await?;
}
},
Err(error) => log::error!(
Expand Down Expand Up @@ -366,8 +371,9 @@ async fn process_agreement(

let _ = market.send(message).await?;
}
AgreementResponse::RejectAgreement => {
api.reject_agreement(&agreement.agreement_id).await?;
AgreementResponse::RejectAgreement { reason } => {
api.reject_agreement(&agreement.agreement_id, reason.map(|r| Reason::new(r)))
.await?;
}
},
Err(error) => log::error!(
Expand Down
1 change: 1 addition & 0 deletions core/market/src/db/model/agreement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ impl Agreement {
.map(|d| DateTime::<Utc>::from_utc(d, Utc)),
state: self.state.into(),
timestamp: Utc.from_utc_datetime(&self.creation_ts),
app_session_id: None,
proposed_signature: self.proposed_signature,
approved_signature: self.approved_signature,
committed_signature: self.committed_signature,
Expand Down
1 change: 1 addition & 0 deletions core/payment/examples/payment_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ async fn main() -> anyhow::Result<()> {
approved_date: None,
state: market::agreement::State::Proposal,
timestamp: Utc::now(),
app_session_id: None,
proposed_signature: None,
approved_signature: None,
committed_signature: None,
Expand Down

0 comments on commit e0d0944

Please sign in to comment.