Skip to content
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

Merged
merged 3 commits into from
Dec 18, 2024
Merged

Track credits usage #119

merged 3 commits into from
Dec 18, 2024

Conversation

Abdullah13521
Copy link
Contributor

@Abdullah13521 Abdullah13521 commented Dec 17, 2024

Description

Addresses this issue

Example of frontend display
Screenshot 2024-12-17 at 10 48 54 PM

Type of change

  • 🚨 Breaking change - causes existing functionality to break (triggers MAJOR version bump)
  • ✨ New feature - adds functionality in a non-breaking way (triggers MINOR version bump)
  • 🐛 Bug fix - fixes an issue without changing functionality (triggers PATCH version bump)
  • 🏠 Internal - changes that don't affect external functionality (no version bump)
    (e.g., refactoring, docs, tests, admin site changes)

Release Impact

  • Current version:
  • Next version will be:

Checklist

  • My code follows the style guidelines
  • My code is tested with 99%+ coverage
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have updated the documentation to reflect my changes
  • I have added/updated tests to cover my changes

Breaking Changes

Migration Guide

Additional Notes

@Abdullah13521 Abdullah13521 self-assigned this Dec 17, 2024
@Abdullah13521 Abdullah13521 added the cloud-only changes only to the cloud branch label Dec 17, 2024
@@ -100,6 +120,19 @@ def record_consumed_credits(self, credits):
f"Error recording consumed credits for {self.email}", "fatal"
)

def record_credit_usage(
Copy link
Contributor

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)(
Copy link
Contributor

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

Copy link
Contributor

@Jonathan-Adly Jonathan-Adly left a 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

@Jonathan-Adly Jonathan-Adly merged commit adfec81 into cloud Dec 18, 2024
1 check passed
@Jonathan-Adly Jonathan-Adly deleted the track-credits branch December 18, 2024 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cloud-only changes only to the cloud branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants