refactor handle_response in service/sending

Early returns good.
This commit is contained in:
Charles Hall 2024-06-23 17:56:05 -07:00
parent f2e5b281c9
commit e13db834ed
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF

View file

@ -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),