Skip to content

Commit 60a29b6

Browse files
authored
Fix: Improve quota notification and blocking logic (#489)
* 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. * Suppress magic number lint warning in logger Added an ESLint directive to ignore the magic number warning for the percentage calculation in the workspace events limit log message.
1 parent 14bb0e7 commit 60a29b6

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

workers/limiter/src/index.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,31 @@ 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+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
295+
this.logger.info(`Workspace ${workspace._id} is about to reach events limit: ${Math.floor(usedQuota * 100)}% used`);
296+
285297
/**
286298
* Add task for Sender worker
287299
*/

0 commit comments

Comments
 (0)