@@ -108,6 +108,8 @@ export default class LimiterWorker extends Worker {
108108 * @param event - event to handle
109109 */
110110 private async handleBlockWorkspaceEvent ( event : BlockWorkspaceEvent ) : Promise < void > {
111+ this . logger . info ( 'handle block workspace event' , event ) ;
112+
111113 const workspace = await this . dbHelper . getWorkspacesWithTariffPlans ( event . workspaceId ) ;
112114
113115 if ( ! workspace ) {
@@ -126,7 +128,13 @@ export default class LimiterWorker extends Worker {
126128 const workspaceProjects = await this . dbHelper . getProjects ( event . workspaceId ) ;
127129 const projectIds = workspaceProjects . map ( project => project . _id . toString ( ) ) ;
128130
129- await this . dbHelper . changeWorkspaceBlockedState ( event . workspaceId , true ) ;
131+ const { updatedWorkspace } = await this . prepareWorkspaceUsageUpdate ( workspace , workspaceProjects ) ;
132+
133+ updatedWorkspace . isBlocked = true ;
134+ await this . dbHelper . updateWorkspacesEventsCountAndIsBlocked ( [ updatedWorkspace ] ) ;
135+
136+ this . logger . info ( 'workspace blocked in db ' , event . workspaceId )
137+
130138 await this . redis . appendBannedProjects ( projectIds ) ;
131139
132140 this . sendSingleWorkspaceReport ( workspaceProjects , workspace , 'blocked' ) ;
@@ -159,16 +167,18 @@ export default class LimiterWorker extends Worker {
159167 /**
160168 * If workspace should be blocked by quota - then do not unblock it
161169 */
162- const { shouldBeBlockedByQuota } = await this . prepareWorkspaceUsageUpdate ( workspace , workspaceProjects ) ;
170+ const { shouldBeBlockedByQuota, updatedWorkspace } = await this . prepareWorkspaceUsageUpdate ( workspace , workspaceProjects ) ;
163171
164172 if ( shouldBeBlockedByQuota ) {
165173 return ;
166174 }
167175
168- await this . dbHelper . changeWorkspaceBlockedState ( event . workspaceId , false ) ;
176+ updatedWorkspace . isBlocked = false ;
177+
178+ await this . dbHelper . updateWorkspacesEventsCountAndIsBlocked ( [ updatedWorkspace ] ) ;
169179 await this . redis . removeBannedProjects ( projectIds ) ;
170180
171- this . sendSingleWorkspaceReport ( workspaceProjects , workspace , 'unblocked' ) ;
181+ this . sendSingleWorkspaceReport ( workspaceProjects , updatedWorkspace , 'unblocked' ) ;
172182 }
173183
174184 /**
@@ -229,6 +239,8 @@ export default class LimiterWorker extends Worker {
229239 private async prepareWorkspaceUsageUpdate (
230240 workspace : WorkspaceWithTariffPlan , projects : ProjectDBScheme [ ]
231241 ) : Promise < WorkspaceReport > {
242+ this . logger . info ( 'prepareWorkspaceUsageUpdate' ) ;
243+
232244 /**
233245 * If last charge date is not specified, then we skip checking it
234246 * In the next time the Paymaster worker starts, it will set lastChargeDate for this workspace
@@ -247,6 +259,9 @@ export default class LimiterWorker extends Worker {
247259 const since = Math . floor ( new Date ( workspace . lastChargeDate ) . getTime ( ) / MS_IN_SEC ) ;
248260
249261 const workspaceEventsCount = await this . dbHelper . getEventsCountByProjects ( projects , since ) ;
262+
263+ this . logger . info ( `workspace ${ workspace . _id } events count since last charge date: ${ workspaceEventsCount } ` ) ;
264+
250265 const usedQuota = workspaceEventsCount / workspace . tariffPlan . eventsLimit ;
251266 const quotaNotification = NOTIFY_ABOUT_LIMIT . reverse ( ) . find ( quota => quota < usedQuota ) ;
252267
0 commit comments