mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 19:54:13 +00:00
fix(proxy/utils.py): fix reset budget logic
uses fewer clients - prevents read timeouts
This commit is contained in:
parent
6a62cfe48c
commit
2f022920f1
1 changed files with 10 additions and 25 deletions
|
@ -1820,34 +1820,19 @@ async def reset_budget(prisma_client: PrismaClient):
|
||||||
if prisma_client is not None:
|
if prisma_client is not None:
|
||||||
### RESET KEY BUDGET ###
|
### RESET KEY BUDGET ###
|
||||||
now = datetime.utcnow()
|
now = datetime.utcnow()
|
||||||
keys_to_reset = await prisma_client.get_data(
|
asyncio.create_task(
|
||||||
table_name="key", query_type="find_all", expires=now, reset_at=now
|
prisma_client.db.litellm_verificationtoken.update_many(
|
||||||
|
where={"budget_reset_at": {"lt": now}},
|
||||||
|
data={"spend": 0, "budget_reset_at": now},
|
||||||
)
|
)
|
||||||
|
|
||||||
if keys_to_reset is not None and len(keys_to_reset) > 0:
|
|
||||||
for key in keys_to_reset:
|
|
||||||
key.spend = 0.0
|
|
||||||
duration_s = _duration_in_seconds(duration=key.budget_duration)
|
|
||||||
key.budget_reset_at = now + timedelta(seconds=duration_s)
|
|
||||||
|
|
||||||
await prisma_client.update_data(
|
|
||||||
query_type="update_many", data_list=keys_to_reset, table_name="key"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
### RESET USER BUDGET ###
|
### RESET USER BUDGET ###
|
||||||
now = datetime.utcnow()
|
asyncio.create_task(
|
||||||
users_to_reset = await prisma_client.get_data(
|
prisma_client.db.litellm_usertable.update_many(
|
||||||
table_name="user", query_type="find_all", reset_at=now
|
where={"budget_reset_at": {"lt": now}},
|
||||||
|
data={"spend": 0, "budget_reset_at": now},
|
||||||
)
|
)
|
||||||
|
|
||||||
if users_to_reset is not None and len(users_to_reset) > 0:
|
|
||||||
for user in users_to_reset:
|
|
||||||
user.spend = 0.0
|
|
||||||
duration_s = _duration_in_seconds(duration=user.budget_duration)
|
|
||||||
user.budget_reset_at = now + timedelta(seconds=duration_s)
|
|
||||||
|
|
||||||
await prisma_client.update_data(
|
|
||||||
query_type="update_many", data_list=users_to_reset, table_name="user"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue