Skip to content

Commit 7c6c1aa

Browse files
committed
Improve quota notification and blocking logic
Refactored the quota check to ensure workspaces are blocked and notified only when appropriate. Added logging for both blocking and approaching quota limits, and clarified notification task handling.
1 parent 14bb0e7 commit 7c6c1aa

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

workers/limiter/src/index.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,30 @@ export default class LimiterWorker extends Worker {
269269
const isAlreadyBlocked = workspace.isBlocked;
270270

271271
/**
272-
* Send notification if workspace will be blocked cause events limit
272+
* Check quota and send notifications if needed
273+
* - if should be blocked by quota and is not blocked yet -> block and notify
274+
* - if is about to reach limit -> notify
273275
*/
274-
if (!isAlreadyBlocked && shouldBeBlockedByQuota) {
276+
if (shouldBeBlockedByQuota) {
277+
if (!isAlreadyBlocked) {
278+
this.logger.info(`Workspace ${workspace._id} will be blocked by quota: ${workspaceEventsCount} of ${workspace.tariffPlan.eventsLimit} events used`);
279+
280+
/**
281+
* Add task for Sender worker
282+
*/
283+
await this.addTask(WorkerNames.EMAIL, {
284+
type: 'block-workspace',
285+
payload: {
286+
workspaceId: workspace._id,
287+
},
288+
});
289+
}
290+
} else if (quotaNotification) {
275291
/**
276-
* Add task for Sender worker
292+
* Notify that workspace is about to reach events limit
277293
*/
278-
await this.addTask(WorkerNames.EMAIL, {
279-
type: 'block-workspace',
280-
payload: {
281-
workspaceId: workspace._id,
282-
},
283-
});
284-
} else if (quotaNotification) {
294+
this.logger.info(`Workspace ${workspace._id} is about to reach events limit: ${Math.floor(usedQuota * 100)}% used`);
295+
285296
/**
286297
* Add task for Sender worker
287298
*/

0 commit comments

Comments
 (0)