@@ -115,13 +115,20 @@ export default class LimiterWorker extends Worker {
115115 return ;
116116 }
117117
118+ /**
119+ * If workspace is already blocked - do nothing
120+ */
121+ if ( workspace . isBlocked ) {
122+ return ;
123+ }
124+
118125 const workspaceProjects = await this . dbHelper . getProjects ( event . workspaceId ) ;
119126 const projectIds = workspaceProjects . map ( project => project . _id . toString ( ) ) ;
120127
121128 await this . dbHelper . changeWorkspaceBlockedState ( event . workspaceId , true ) ;
122129 await this . redis . appendBannedProjects ( projectIds ) ;
123130
124- this . sendSingleWorkspaceReport ( workspaceProjects , workspace , 'Blocked ' ) ;
131+ this . sendSingleWorkspaceReport ( workspaceProjects , workspace , 'blocked ' ) ;
125132 }
126133
127134 /**
@@ -137,6 +144,13 @@ export default class LimiterWorker extends Worker {
137144 return ;
138145 }
139146
147+ /**
148+ * If workspace is already unblocked - do nothing
149+ */
150+ if ( workspace . isBlocked === false ) {
151+ return ;
152+ }
153+
140154 const workspaceProjects = await this . dbHelper . getProjects ( event . workspaceId ) ;
141155 const projectIds = workspaceProjects . map ( project => project . _id . toString ( ) ) ;
142156
@@ -152,7 +166,7 @@ export default class LimiterWorker extends Worker {
152166 await this . dbHelper . changeWorkspaceBlockedState ( event . workspaceId , false ) ;
153167 await this . redis . removeBannedProjects ( projectIds ) ;
154168
155- this . sendSingleWorkspaceReport ( workspaceProjects , workspace , 'Unblocked ' ) ;
169+ this . sendSingleWorkspaceReport ( workspaceProjects , workspace , 'unblocked ' ) ;
156170 }
157171
158172 /**
@@ -185,7 +199,7 @@ export default class LimiterWorker extends Worker {
185199 const projectIds = projectsToUpdate . map ( project => project . _id . toString ( ) ) ;
186200
187201 this . redis . appendBannedProjects ( projectIds ) ;
188- message += this . formSingleWorkspaceMessage ( workspace , projectsToUpdate , 'Blocked ' ) ;
202+ message += this . formSingleWorkspaceMessage ( workspace , projectsToUpdate , 'blocked ' ) ;
189203 }
190204 } ) ) ;
191205
@@ -277,16 +291,17 @@ export default class LimiterWorker extends Worker {
277291 * @param type - workspace was blocked or unblocked
278292 * @returns {string } formatted html string
279293 */
280- private formSingleWorkspaceMessage ( workspace : WorkspaceWithTariffPlan , projects : ProjectDBScheme [ ] , type : 'Blocked' | 'Unblocked' ) : string {
281- let message = `<b>${ type } ${ workspace . name } (id: ${ workspace . _id } )
282- quota: ${ workspace . billingPeriodEventsCount } of ${ workspace . tariffPlan . eventsLimit } </b>\n` ;
294+ private formSingleWorkspaceMessage ( workspace : WorkspaceWithTariffPlan , projects : ProjectDBScheme [ ] , type : 'blocked' | 'unblocked' ) : string {
295+ const statusEmoji = type === 'blocked' ? '⛔️' : '✅' ;
283296
284- if ( projects . length === 0 ) {
285- message += `<code>none, projects are already stored in redis</code> `;
297+ let message = ` ${ statusEmoji } Workspace <b> ${ workspace . name } </b> ${ type } <b>(id: <code> ${ workspace . _id } </code>)</b>\n\n\
298+ Quota: ${ workspace . billingPeriodEventsCount } of ${ workspace . tariffPlan . eventsLimit } </b>\n\n `;
286299
300+ if ( projects . length === 0 ) {
287301 return message ;
288302 }
289303
304+ message += `Project ids ${ type === 'blocked' ? 'added' : 'removed' } from Redis:\n` ;
290305 message += `${ projects . map ( project => `• ${ project . name } (id: <code>${ project . _id } </code>)` ) . join ( '\n' ) } ` ;
291306
292307 return message ;
@@ -299,10 +314,10 @@ export default class LimiterWorker extends Worker {
299314 * @param workspace - blocked or unblocked workspace
300315 * @param type - workspace was blocked or unblocked
301316 */
302- private sendSingleWorkspaceReport ( projects : ProjectDBScheme [ ] , workspace : WorkspaceWithTariffPlan , type : 'Blocked ' | 'Unblocked ' ) : void {
317+ private sendSingleWorkspaceReport ( projects : ProjectDBScheme [ ] , workspace : WorkspaceWithTariffPlan , type : 'blocked ' | 'unblocked ' ) : void {
303318 const message = this . formSingleWorkspaceMessage ( workspace , projects , type ) ;
304319
305- telegram . sendMessage ( `🔐 <b>[ Limiter / Single ]</b>\n ${ message } ` , telegram . TelegramBotURLs . Limiter ) ;
320+ telegram . sendMessage ( `${ message } ` , telegram . TelegramBotURLs . Limiter ) ;
306321 }
307322
308323 /**
0 commit comments