From f0927faf6151211ecb5b14faf7c9c3fdca66abb8 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Tue, 29 Jul 2025 18:45:00 -0400 Subject: [PATCH] collab: Add kill switches for syncing data to and from Stripe (#35304) This PR adds two kill switches for syncing data to and from Stripe using Collab. The `cloud-stripe-events-polling` and `cloud-stripe-usage-meters-sync` feature flags control whether we use Cloud for polling Stripe events and updating Stripe meters, respectively. When we're ready to hand off the syncing to Cloud we can enable the feature flag to do so. Release Notes: - N/A --- crates/collab/src/api/billing.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/collab/src/api/billing.rs b/crates/collab/src/api/billing.rs index 1cb20173c1..9d0c617ab9 100644 --- a/crates/collab/src/api/billing.rs +++ b/crates/collab/src/api/billing.rs @@ -87,6 +87,14 @@ async fn poll_stripe_events( stripe_client: &Arc, real_stripe_client: &stripe::Client, ) -> anyhow::Result<()> { + let feature_flags = app.db.list_feature_flags().await?; + let sync_events_using_cloud = feature_flags + .iter() + .any(|flag| flag.flag == "cloud-stripe-events-polling" && flag.enabled_for_all); + if sync_events_using_cloud { + return Ok(()); + } + fn event_type_to_string(event_type: EventType) -> String { // Calling `to_string` on `stripe::EventType` members gives us a quoted string, // so we need to unquote it. @@ -569,6 +577,14 @@ async fn sync_model_request_usage_with_stripe( llm_db: &Arc, stripe_billing: &Arc, ) -> anyhow::Result<()> { + let feature_flags = app.db.list_feature_flags().await?; + let sync_model_request_usage_using_cloud = feature_flags + .iter() + .any(|flag| flag.flag == "cloud-stripe-usage-meters-sync" && flag.enabled_for_all); + if sync_model_request_usage_using_cloud { + return Ok(()); + } + log::info!("Stripe usage sync: Starting"); let started_at = Utc::now();