improve code

This commit is contained in:
houseme
2025-04-22 09:14:09 +08:00
parent 6c70c03985
commit 0ed92b3b6f
12 changed files with 257 additions and 36 deletions
+3 -10
View File
@@ -38,17 +38,12 @@ impl KafkaAdapter {
let payload = serde_json::to_string(&event)?;
for attempt in 0..self.max_retries {
let record = FutureRecord::to(&self.topic)
.key(&event_id)
.payload(&payload);
let record = FutureRecord::to(&self.topic).key(&event_id).payload(&payload);
match self.producer.send(record, Timeout::Never).await {
Ok(_) => return Ok(()),
Err((KafkaError::MessageProduction(RDKafkaErrorCode::QueueFull), _)) => {
tracing::warn!(
"Kafka attempt {} failed: Queue full. Retrying...",
attempt + 1
);
tracing::warn!("Kafka attempt {} failed: Queue full. Retrying...", attempt + 1);
sleep(Duration::from_secs(2u64.pow(attempt))).await;
}
Err((e, _)) => {
@@ -58,9 +53,7 @@ impl KafkaAdapter {
}
}
Err(Error::Custom(
"Exceeded maximum retry attempts for Kafka message".to_string(),
))
Err(Error::Custom("Exceeded maximum retry attempts for Kafka message".to_string()))
}
}
@@ -45,6 +45,7 @@ impl ChannelAdapter for WebhookAdapter {
async fn send(&self, event: &Event) -> Result<(), Error> {
let mut attempt = 0;
tracing::info!("Attempting to send webhook request: {:?}", event);
loop {
match self.build_request(event).send().await {
Ok(response) => {