This commit is contained in:
1 parent
d74db2096c
commit
8c763786c1
25 files changed
+3614
-407
No files matched your search
@@ -14,10 +14,7 @@ use tracing::{info, instrument};
|
||||
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use apalis::prelude::Storage;
|
||||
|
||||
use crate::consts::{GITEA_EVENT_TYPE_HEADER_NAME, GITEA_SIG_HEADER_NAME, MAX_WEBHOOK_BODY_SIZE};
|
||||
use crate::dedup::{Dedup, WEBHOOK_TTL};
|
||||
use crate::errors::AppError;
|
||||
use crate::gitea::WebhookType;
|
||||
use crate::metrics;
|
||||
@@ -64,20 +61,19 @@ async fn webhook(
|
||||
metrics::webhook_received(event_type);
|
||||
|
||||
let event_id = wb.event_id();
|
||||
let webhook_key = Dedup::webhook_key(event_id);
|
||||
if !app_state
|
||||
.dedup
|
||||
.claim(&webhook_key, WEBHOOK_TTL)
|
||||
.await
|
||||
.map_err(anyhow::Error::from)?
|
||||
{
|
||||
metrics::webhook_duplicate(event_type);
|
||||
return Err(AppError::AlreadyProcessedErr);
|
||||
match app_state.dedup.is_known(event_id).await {
|
||||
Ok(true) => {
|
||||
metrics::webhook_duplicate(event_type);
|
||||
return Err(AppError::AlreadyProcessedErr);
|
||||
}
|
||||
Ok(false) => {}
|
||||
Err(err) => {
|
||||
metrics::webhook_enqueue_failed(event_type);
|
||||
return Err(AppError::EnqueueErr(anyhow::Error::from(err)));
|
||||
}
|
||||
}
|
||||
|
||||
let mut storage = app_state.storage.clone();
|
||||
if let Err(err) = storage.push(wb).await {
|
||||
app_state.dedup.release(&webhook_key).await.ok();
|
||||
if let Err(err) = app_state.queue.push(wb).await {
|
||||
metrics::webhook_enqueue_failed(event_type);
|
||||
return Err(AppError::EnqueueErr(anyhow::Error::from(err)));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user