-
Notifications
You must be signed in to change notification settings - Fork 48
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
Track credits usage #119
Track credits usage #119
Conversation
web/accounts/models.py
Outdated
@@ -100,6 +120,19 @@ def record_consumed_credits(self, credits): | |||
f"Error recording consumed credits for {self.email}", "fatal" | |||
) | |||
|
|||
def record_credit_usage( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - this is easy to make async, and will make things cleaner when we use in the view. Can we change it?
web/api/views.py
Outdated
@@ -1465,6 +1503,11 @@ async def consume_credits(request, available_credits, consumed_credits): | |||
f"Set available credits to 0 and recorded {consumed_credits - available_credits} consumed credits" | |||
) | |||
|
|||
# track credit usage | |||
await sync_to_async(request.auth.record_credit_usage)( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified and cleaner if we make record_credit_usage async
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the async change and this should be ready to go
Description
Addresses this issue
Example of frontend display

Type of change
(e.g., refactoring, docs, tests, admin site changes)
Release Impact
Checklist
Breaking Changes
Migration Guide
Additional Notes