From 9abeedf0c6e0ef237c97d9885471777054fd6c33 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Mon, 28 Apr 2025 18:37:18 -0400 Subject: [PATCH] collab: Rename symbols for existing Stripe synchronization (#29570) This PR renames the symbols for the existing Stripe synchronization. This will make things clearer once the new synchronization job for the new billing is added. Release Notes: - N/A --- crates/collab/src/api/billing.rs | 14 ++++++++------ crates/collab/src/main.rs | 4 ++-- crates/collab/src/stripe_billing.rs | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/collab/src/api/billing.rs b/crates/collab/src/api/billing.rs index b635f3daa14198ae9f6b694f5c8c28191a7cc666..507c3435d01071d4d1d4e61d830c4cf7c87faf2a 100644 --- a/crates/collab/src/api/billing.rs +++ b/crates/collab/src/api/billing.rs @@ -1243,9 +1243,9 @@ async fn find_or_create_billing_customer( Ok(Some(billing_customer)) } -const SYNC_LLM_USAGE_WITH_STRIPE_INTERVAL: Duration = Duration::from_secs(60); +const SYNC_LLM_TOKEN_USAGE_WITH_STRIPE_INTERVAL: Duration = Duration::from_secs(60); -pub fn sync_llm_usage_with_stripe_periodically(app: Arc) { +pub fn sync_llm_token_usage_with_stripe_periodically(app: Arc) { let Some(stripe_billing) = app.stripe_billing.clone() else { log::warn!("failed to retrieve Stripe billing object"); return; @@ -1260,17 +1260,19 @@ pub fn sync_llm_usage_with_stripe_periodically(app: Arc) { let executor = executor.clone(); async move { loop { - sync_with_stripe(&app, &llm_db, &stripe_billing) + sync_token_usage_with_stripe(&app, &llm_db, &stripe_billing) .await .context("failed to sync LLM usage to Stripe") .trace_err(); - executor.sleep(SYNC_LLM_USAGE_WITH_STRIPE_INTERVAL).await; + executor + .sleep(SYNC_LLM_TOKEN_USAGE_WITH_STRIPE_INTERVAL) + .await; } } }); } -async fn sync_with_stripe( +async fn sync_token_usage_with_stripe( app: &Arc, llm_db: &Arc, stripe_billing: &Arc, @@ -1306,7 +1308,7 @@ async fn sync_with_stripe( .subscribe_to_model(&stripe_subscription_id, &stripe_model) .await?; stripe_billing - .bill_model_usage(&stripe_customer_id, &stripe_model, &event) + .bill_model_token_usage(&stripe_customer_id, &stripe_model, &event) .await?; llm_db.consume_billing_event(event.id).await?; } diff --git a/crates/collab/src/main.rs b/crates/collab/src/main.rs index a363d556a1fd9cbe24cd59635ba046e8a6b08f22..25befc28459ff036f605a3d3a070189f4d48137f 100644 --- a/crates/collab/src/main.rs +++ b/crates/collab/src/main.rs @@ -8,7 +8,7 @@ use axum::{ }; use collab::api::CloudflareIpCountryHeader; -use collab::api::billing::sync_llm_usage_with_stripe_periodically; +use collab::api::billing::sync_llm_token_usage_with_stripe_periodically; use collab::llm::db::LlmDatabase; use collab::migrations::run_database_migrations; use collab::user_backfiller::spawn_user_backfiller; @@ -152,7 +152,7 @@ async fn main() -> Result<()> { if let Some(mut llm_db) = llm_db { llm_db.initialize().await?; - sync_llm_usage_with_stripe_periodically(state.clone()); + sync_llm_token_usage_with_stripe_periodically(state.clone()); } app = app diff --git a/crates/collab/src/stripe_billing.rs b/crates/collab/src/stripe_billing.rs index 97c6ee4fb898299984344e3a1f7fe14d30d57848..e992187a9c58a620f2b58e356b6e69537f8dd30e 100644 --- a/crates/collab/src/stripe_billing.rs +++ b/crates/collab/src/stripe_billing.rs @@ -268,7 +268,7 @@ impl StripeBilling { Ok(()) } - pub async fn bill_model_usage( + pub async fn bill_model_token_usage( &self, customer_id: &stripe::CustomerId, model: &StripeModel,