Merge pull request #782 from tnfssc/fix/billing-system

fix(billing): update monthly usage calculation to exclude running jobs older than one hour
This commit is contained in:
Bobbie 2025-06-22 13:39:47 +05:30 committed by GitHub
commit edd2aa1342
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 2 deletions

View File

@ -195,7 +195,10 @@ 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
# 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)