mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
collab: Ignore Stripe events that are older than an hour (#15830)
This PR makes it so any Stripe events we receive that occurred over an hour ago are marked as processed. We don't want to process an old event long after it occurred and potentially overwrite more recent updates. This also makes running collab locally a bit nicer, as we won't be getting errors for a bunch of older events that will never get processed successfully. The period after time after which we consider an event "stale" can be modified, as needed. Release Notes: - N/A
This commit is contained in:
parent
f6a0fef5cf
commit
4ed43e6e6f
@ -8,7 +8,7 @@ use axum::{
|
||||
routing::{get, post},
|
||||
Extension, Json, Router,
|
||||
};
|
||||
use chrono::{DateTime, SecondsFormat};
|
||||
use chrono::{DateTime, SecondsFormat, Utc};
|
||||
use reqwest::StatusCode;
|
||||
use sea_orm::ActiveValue;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -427,6 +427,24 @@ async fn poll_stripe_events(
|
||||
stripe_event_created_timestamp: event.created,
|
||||
};
|
||||
|
||||
// If the event has happened too far in the past, we don't want to
|
||||
// process it and risk overwriting other more-recent updates.
|
||||
//
|
||||
// 1 hour was chosen arbitrarily. This could be made longer or shorter.
|
||||
let one_hour = Duration::from_secs(60 * 60);
|
||||
let an_hour_ago = Utc::now() - one_hour;
|
||||
if an_hour_ago.timestamp() > event.created {
|
||||
log::info!(
|
||||
"Stripe event {} is more than {one_hour:?} old, marking as processed",
|
||||
event_id
|
||||
);
|
||||
app.db
|
||||
.create_processed_stripe_event(&processed_event_params)
|
||||
.await?;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let process_result = match event.type_ {
|
||||
EventType::CustomerCreated | EventType::CustomerUpdated => {
|
||||
handle_customer_event(app, stripe_client, event).await
|
||||
|
Loading…
Reference in New Issue
Block a user