Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions workers/limiter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,31 @@ export default class LimiterWorker extends Worker {
const isAlreadyBlocked = workspace.isBlocked;

/**
* Send notification if workspace will be blocked cause events limit
* Check quota and send notifications if needed
* - if should be blocked by quota and is not blocked yet -> block and notify
* - if is about to reach limit -> notify
*/
if (!isAlreadyBlocked && shouldBeBlockedByQuota) {
if (shouldBeBlockedByQuota) {
if (!isAlreadyBlocked) {
this.logger.info(`Workspace ${workspace._id} will be blocked by quota: ${workspaceEventsCount} of ${workspace.tariffPlan.eventsLimit} events used`);

/**
* Add task for Sender worker
*/
await this.addTask(WorkerNames.EMAIL, {
type: 'block-workspace',
payload: {
workspaceId: workspace._id,
},
});
}
} else if (quotaNotification) {
/**
* Add task for Sender worker
* Notify that workspace is about to reach events limit
*/
await this.addTask(WorkerNames.EMAIL, {
type: 'block-workspace',
payload: {
workspaceId: workspace._id,
},
});
} else if (quotaNotification) {
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
this.logger.info(`Workspace ${workspace._id} is about to reach events limit: ${Math.floor(usedQuota * 100)}% used`);

/**
* Add task for Sender worker
*/
Expand Down
Loading