From d39753d9772c749cc6408f8e3831a49946b6841b Mon Sep 17 00:00:00 2001 From: sharath <29162020+tnfssc@users.noreply.github.com> Date: Sun, 22 Jun 2025 08:04:36 +0000 Subject: [PATCH] fix(billing): update monthly usage calculation to exclude running jobs older than one hour --- backend/services/billing.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/services/billing.py b/backend/services/billing.py index 4b49a6a9..6111f280 100644 --- a/backend/services/billing.py +++ b/backend/services/billing.py @@ -195,8 +195,11 @@ async def calculate_monthly_usage(client, user_id: str) -> float: if run['completed_at']: end_time = datetime.fromisoformat(run['completed_at'].replace('Z', '+00:00')).timestamp() else: - # For running jobs, use current time - end_time = now_ts + # if the start time is more than an hour ago, don't consider that time in total. else use the current time + if start_time < now_ts - 3600: + continue + else: + end_time = now_ts total_seconds += (end_time - start_time)