fix(billing): update monthly usage calculation to exclude running jobs older than one hour

This commit is contained in:
sharath 2025-06-22 08:04:36 +00:00
parent 1c9573dc31
commit d39753d977
No known key found for this signature in database
1 changed files with 5 additions and 2 deletions

View File

@ -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)