-
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
Provider - check debit notes acceptance #897
Conversation
…check-debit-notes-acceptance
…which uses dynamic negotiation logic
0a2757b
to
b698012
Compare
…o breaking Agreement
…check-debit-notes-acceptance
2b361aa
to
56b32a5
Compare
let result = self.components.negotiate_step(&proposal, offer_proposal)?; | ||
match result { | ||
NegotiationResult::Reject { reason } => Ok(ProposalResponse::RejectProposal { reason }), | ||
NegotiationResult::Ready { offer } | NegotiationResult::Negotiating { offer } => { | ||
let offer = NewOffer { | ||
properties: serde_json::Value::Object(flatten(offer.json)), | ||
constraints, | ||
}; | ||
Ok(ProposalResponse::CounterProposal { offer }) | ||
} | ||
} |
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.
Error should result in Rejecting Proposal. (Can be done in different PR)
e026270
to
8d98376
Compare
}, | ||
); | ||
|
||
self.update_deadline(ctx).unwrap(); |
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.
Unwrap inside
self.deadlines.insert(msg.agreement_id.to_string(), vec![]); | ||
} | ||
|
||
let deadlines = self.deadlines.get_mut(&msg.agreement_id).unwrap(); |
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.
Maybe entry
min_agreement_expiration: std::time::Duration::from_secs(5 * 60), | ||
max_agreement_expiration: std::time::Duration::from_secs(30 * 60), | ||
max_agreement_expiration_without_deadline: std::time::Duration::from_secs(10 * 60), | ||
debit_note_acceptance_deadline: std::time::Duration::from_secs(120), |
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.
debit_note_acceptance_deadline: std::time::Duration::from_secs(120), | |
debit_note_acceptance_timeout: std::time::Duration::from_secs(120), |
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.
All of my comments are about readability only.
Still, I've tested it E2E and accept this PR in its current form.
fn debit_deadline_from(proposal: &ProposalView) -> Result<Option<Duration>> { | ||
match proposal.pointer_typed::<i64>("/golem/com/payment/debit-notes/acceptance-timeout") { | ||
// Requestor is able to accept DebitNotes, because he set this property. | ||
Ok(deadline) => Ok(Some(Duration::seconds(deadline))), |
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.
Ok(deadline) => Ok(Some(Duration::seconds(deadline))), | |
Ok(timeout) => Ok(Some(Duration::seconds(timeout))), |
Ok(Utc.timestamp_millis(timestamp)) | ||
} | ||
|
||
fn debit_deadline_from(proposal: &ProposalView) -> Result<Option<Duration>> { |
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.
fn debit_deadline_from(proposal: &ProposalView) -> Result<Option<Duration>> { | |
fn debit_timeout_from(proposal: &ProposalView) -> Result<Option<Duration>> { |
// Requestor doesn't support DebitNotes acceptance, so we should | ||
// remove our property from Proposal to match with his. | ||
(None, Some(_)) => { | ||
offer.remove_property("/golem/com/payment/debit-notes/acceptance-timeout")?; |
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.
introduce Constant
pub payment_model: Arc<dyn PaymentModel>, | ||
pub activities: HashMap<String, ActivityPayment>, | ||
|
||
pub update_interval: std::time::Duration, | ||
pub payment_deadline: Option<chrono::Duration>, |
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.
pub payment_deadline: Option<chrono::Duration>, | |
pub payment_timeout: Option<chrono::Duration>, |
@@ -95,7 +100,16 @@ impl AgreementPayment { | |||
pub fn new(agreement: &AgreementView) -> Result<AgreementPayment> { | |||
let payment_description = PaymentDescription::new(agreement)?; | |||
let update_interval = payment_description.get_update_interval()?; | |||
let payment_model = PaymentModelFactory::create(payment_description)?; | |||
let debit_deadline = payment_description.get_debit_note_deadline()?; |
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.
let debit_deadline = payment_description.get_debit_note_deadline()?; | |
let debit_timeout = payment_description.get_debit_note_deadline()?; |
#[rtype(result = "()")] | ||
pub struct DeadlineElapsed { | ||
pub agreement_id: String, | ||
pub deadline: DateTime<Utc>, |
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.
here the deadline
is proper name, as it's describing specific point of the time
@@ -216,18 +244,38 @@ async fn send_debit_note( | |||
&debit_note_info.activity_id | |||
); | |||
|
|||
if let Some(deadline) = debit_note_info | |||
.payment_deadline | |||
.map(|deadline| Utc::now() + deadline) |
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.
.map(|deadline| Utc::now() + deadline) | |
.map(|timeout| Utc::now() + timeout) |
resolves: #886
ResponseFuture
.It would be good to update rest of actix dependencies.