-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: Allow key budgets to be reset #1567
Labels
enhancement
New feature or request
Comments
Tentative backend code: Install APScheduler: pip install apscheduler Edit your from apscheduler.schedulers.asyncio import AsyncIOScheduler
scheduler = AsyncIOScheduler()
@scheduler.scheduled_job('interval', days=30)
async def reset_budgets():
now = datetime.datetime.utcnow()
keys_to_reset = await prisma.apiKey.find_many(
where={
'resetAt': {
'lt': now
},
}
)
for key in keys_to_reset:
key.budget = initial_budget
key.resetAt = now + datetime.timedelta(days=30)
await prisma.apiKey.update({
'where': {'id': key.id},
'data': key
})
# inside your startup event after prisma.connect()
scheduler.start() |
We'll need to introduce 1 new field into
2 new fields in prisma.schema:
|
ThinkingSample curl curl 'http://0.0.0.0:8000/key/generate' \
--header 'Authorization: Bearer <your-master-key>' \
--header 'Content-Type: application/json' \
--data-raw '{
"team_id": "core-infra", # [OPTIONAL]
"max_budget": 0.0005,
"budget_duration": "10s"
}' |
PR created - #1570 |
29 tasks
PR Merged and passing testing. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Feature
Budgets are set per key, will reset over a time period
Motivation, pitch
allow app owners (i.e. key) to have budgets that reset after a time period
Twitter / LinkedIn details
No response
The text was updated successfully, but these errors were encountered: