mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
refactor handle_response in service/sending
Early returns good.
This commit is contained in:
parent
f2e5b281c9
commit
e13db834ed
1 changed files with 38 additions and 48 deletions
|
|
@ -256,8 +256,23 @@ impl Service {
|
|||
Span::current().record("error", e.to_string());
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(()) => {
|
||||
if let Err(error) = result {
|
||||
warn!(%error, "Marking transaction as failed");
|
||||
current_transaction_status.entry(destination).and_modify(|e| {
|
||||
use TransactionStatus::{Failed, Retrying, Running};
|
||||
|
||||
*e = match e {
|
||||
Running => Failed(1, Instant::now()),
|
||||
Retrying(n) => Failed(*n + 1, Instant::now()),
|
||||
Failed(..) => {
|
||||
error!("Request that was not even running failed?!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
self.db.delete_all_active_requests_for(&destination)?;
|
||||
|
||||
// Find events that have been added since starting the
|
||||
|
|
@ -271,43 +286,18 @@ impl Service {
|
|||
|
||||
if new_events.is_empty() {
|
||||
current_transaction_status.remove(&destination);
|
||||
Ok(None)
|
||||
} else {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
// Insert pdus we found
|
||||
self.db.mark_as_active(&new_events)?;
|
||||
|
||||
Ok(Some(HandlerInputs {
|
||||
destination: destination.clone(),
|
||||
events: new_events
|
||||
.into_iter()
|
||||
.map(|(event, _)| event)
|
||||
.collect(),
|
||||
events: new_events.into_iter().map(|(event, _)| event).collect(),
|
||||
requester_span: None,
|
||||
}))
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
warn!(%error, "Marking transaction as failed");
|
||||
current_transaction_status.entry(destination).and_modify(|e| {
|
||||
*e = match e {
|
||||
TransactionStatus::Running => {
|
||||
TransactionStatus::Failed(1, Instant::now())
|
||||
}
|
||||
TransactionStatus::Retrying(n) => {
|
||||
TransactionStatus::Failed(*n + 1, Instant::now())
|
||||
}
|
||||
TransactionStatus::Failed(..) => {
|
||||
error!(
|
||||
"Request that was not even running failed?!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(
|
||||
skip(self, event_type, key, requester_span, current_transaction_status),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue