-
Notifications
You must be signed in to change notification settings - Fork 46.2k
feat(platform): Deduplicate insufficient funds Discord + email notifications #11672
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
base: dev
Are you sure you want to change the base?
Changes from all commits
4a7bc00
1070650
19969ef
8ead1bb
3cb5c25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -910,6 +910,13 @@ async def _top_up_credits( | |
| metadata=successful_transaction, | ||
| ) | ||
|
|
||
| # Clear insufficient funds notification flags so user can receive | ||
| # Discord alerts again if they run out of funds in the future. | ||
| # Lazy import to avoid circular dependency with executor.manager | ||
| from backend.executor.manager import clear_insufficient_funds_notifications | ||
|
|
||
| clear_insufficient_funds_notifications(user_id) | ||
|
|
||
| async def top_up_intent(self, user_id: str, amount: int) -> str: | ||
| if amount < 500 or amount % 100 != 0: | ||
| raise ValueError( | ||
|
|
@@ -1008,6 +1015,13 @@ async def fulfill_checkout( | |
| metadata=SafeJson(checkout_session), | ||
| ) | ||
|
|
||
| # Clear insufficient funds notification flags so user can receive | ||
| # Discord alerts again if they run out of funds in the future. | ||
| # Lazy import to avoid circular dependency with executor.manager | ||
| from backend.executor.manager import clear_insufficient_funds_notifications | ||
|
|
||
| clear_insufficient_funds_notifications(credit_transaction.userId) | ||
|
||
|
|
||
| async def get_credits(self, user_id: str) -> int: | ||
| balance, _ = await self._get_credits(user_id) | ||
| return balance | ||
|
|
||
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.
The synchronous function
clear_insufficient_funds_notificationsis being called from async context without usingasyncio.to_threador similar mechanisms. This could block the event loop when performing Redis operations (scan_iter and delete). Consider making this function async and usingget_redis_async()instead, or wrap the call inasyncio.to_thread()to avoid blocking the event loop during I/O operations.