imp(limiter): notificaitons on project ban and unban#408
Merged
Conversation
neSpecc
reviewed
May 5, 2025
neSpecc
reviewed
May 12, 2025
slaveeks
approved these changes
May 16, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the workspace block/unblock flow to use explicit limiter events, centralizes database logic, and introduces Telegram-based reporting.
- Adds
block-workspaceandunblock-workspaceevents to the Limiter worker with Telegram notifications. - Updates Paymaster to enqueue Limiter and Email tasks instead of modifying the database directly.
- Extracts DB operations into
DbHelperand adds a Telegram utility for sending reports; test suites are updated accordingly.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| workers/paymaster/src/index.ts | Refactored Paymaster to enqueue limiter/unblock tasks via addTask |
| workers/paymaster/tests/index.test.ts | Updated tests to spy on addTask calls and adjust queue names |
| workers/limiter/src/index.ts | Implemented block-workspace/unblock-workspace handlers, Telegram reports, and regular checks |
| workers/limiter/src/dbHelper.ts | Moved MongoDB operations into a new helper class |
| workers/limiter/types/reportData.ts | Renamed report field isBlocked → shouldBeBlockedByQuota |
| lib/utils/telegram.ts | Added Telegram utility for sending reports via sendMessage |
Comments suppressed due to low confidence (2)
workers/paymaster/src/index.ts:360
- The JSDoc for
unblockWorkspacestill says 'workspace for block'. Please update it to 'workspace to unblock' to match the method's behavior.
* @param workspace - workspace for block
workers/limiter/types/reportData.ts:9
- The comment refers to
isBlockedbut the field is nowshouldBeBlockedByQuota. Update the comment to describe the new field name and semantics.
* Is workspace get blocked
| const updatedWorkspace = await workspacesCollection.findOne({ _id: workspace._id }); | ||
|
|
||
| expect(updatedWorkspace.isBlocked).toEqual(false); | ||
| expect(blockWorkspaceSpy).not.toHaveBeenCalledWith('limiter', { |
There was a problem hiding this comment.
The test checks for calls to the queue named 'limiter', but Paymaster enqueues tasks to 'cron-tasks/limiter'. Update this assertion to use the correct queue name.
Suggested change
| expect(blockWorkspaceSpy).not.toHaveBeenCalledWith('limiter', { | |
| expect(blockWorkspaceSpy).not.toHaveBeenCalledWith('cron-tasks/limiter', { |
| }, | ||
| }); | ||
|
|
||
| expect(blockWorkspaceSpy).not.toHaveBeenCalledWith('email', { |
There was a problem hiding this comment.
The test asserts against the queue 'email', but Paymaster uses 'sender/email'. Update this to match the actual WorkerNames.EMAIL queue name.
Suggested change
| expect(blockWorkspaceSpy).not.toHaveBeenCalledWith('email', { | |
| expect(blockWorkspaceSpy).not.toHaveBeenCalledWith('sender/email', { |
neSpecc
reviewed
May 17, 2025
neSpecc
reviewed
May 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Workspaces Block / Unblock flow
Previous realisation
Limiter
it could also block project in mongo by event limit and then update redis.
Important
Limiter can not unblock workspace in db if it is blocked because in report
isBlocked: isAlreadyBlocked || shouldBeBlockedPaymaster (everything in one flow)
lastChargeDateImportant
Paymaster can not unblock workspace in db if it has tariff plan
API Cloudpayments
and then calls Limiter Single
Problems
isBlockedis inconsistent in redis and db until the moment Limiter is called (in case with manual db updates it could break smth)Who can block?
Who can unblock?
Note
Limiter rewrites the whole set so we can't track which project was actually unblocked
New Block / Unblock flow
Limiter
For each workspace
Paymaster
isBlockednever changes heresubscriptionId- call Limiter BlockAPI Cloudpayments note that this changes will be in a different repo
isBlockednever changes hereResults
Every Block and Unblock happens simultaneously in redis and mongo, and only Limiter controls it
All Workspaces are blocked by
All Workspaces are unblocked by
Important
If you unblock workspace manually do not change
isBlocked, just rechargeisBlockedshould be fully controlled by LimiterFree Workspaces are Unblocked
Additional
DbHelperin for limiter workeryarn test:limiteradd--runInBandbecause added newdbHelper.test.tsit connects to mongo repl set, so should be in same test pipeline withindex.test.tsto avoid initialisation of mongo twice