From 1c04745b96a8c984b9cceb8ee696d5dc66dcbad3 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Tue, 21 Feb 2023 15:19:40 +0200 Subject: [PATCH 1/4] Return user _id for user verification by ws --- workers/loc.api/service.report.framework.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/workers/loc.api/service.report.framework.js b/workers/loc.api/service.report.framework.js index 30d3bb3fa..2117386db 100644 --- a/workers/loc.api/service.report.framework.js +++ b/workers/loc.api/service.report.framework.js @@ -127,7 +127,8 @@ class FrameworkReportService extends ReportService { 'email', 'id', 'isSubAccount', - 'subUsers' + 'subUsers', + '_id' ] } ) From 64b09b010e1357770919feed192b161a43cb4c78 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 22 Feb 2023 11:50:11 +0200 Subject: [PATCH 2/4] Add ability to emit emitCsvGenerationCompletedToOne event by ws --- .../loc.api/ws-transport/ws.event.emitter.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/workers/loc.api/ws-transport/ws.event.emitter.js b/workers/loc.api/ws-transport/ws.event.emitter.js index 2da0e7b33..5fdecd02f 100644 --- a/workers/loc.api/ws-transport/ws.event.emitter.js +++ b/workers/loc.api/ws-transport/ws.event.emitter.js @@ -69,6 +69,24 @@ class WSEventEmitter extends AbstractWSEventEmitter { }) } + emitCsvGenerationCompletedToOne ( + handler = () => {}, + auth = {} + ) { + return this.emit(async (user, ...args) => { + if ( + !Number.isInteger(auth?._id) || + user?._id !== auth?._id + ) { + return { isNotEmitted: true } + } + + return typeof handler === 'function' + ? await handler(user, ...args) + : handler + }, 'emitCsvGenerationCompletedToOne') + } + emitBfxUnamePwdAuthRequiredToOne ( handler = () => {}, auth = {} From a999df1f1cca4484dd28d69ddc833a6d60f99599 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 22 Feb 2023 11:51:41 +0200 Subject: [PATCH 3/4] Send event by ws when csv is ready --- workers/api.framework.report.wrk.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/workers/api.framework.report.wrk.js b/workers/api.framework.report.wrk.js index fb114445a..3339154c9 100644 --- a/workers/api.framework.report.wrk.js +++ b/workers/api.framework.report.wrk.js @@ -147,13 +147,26 @@ class WrkReportFrameWorkApi extends WrkReportServiceApi { ...deps }) + const aggregatorQueue = this.lokue_aggregator.q const conf = this.conf[this.group] const wsTransport = this.container.get(TYPES.WSTransport) + const wsEventEmitter = this.container.get(TYPES.WSEventEmitter) const sync = this.container.get(TYPES.Sync) const processMessageManager = this.container.get(TYPES.ProcessMessageManager) await wsTransport.start() + aggregatorQueue.on('completed', (res) => { + const { csvFilesMetadata, userInfo } = res ?? {} + + wsEventEmitter.emitCsvGenerationCompletedToOne( + { csvFilesMetadata }, + userInfo + ).then(() => {}, (err) => { + this.logger.error(`WS_EVENT_EMITTER:CSV_COMPLETED: ${err.stack || err}`) + }) + }) + if ( !conf.syncMode || !conf.isSchedulerEnabled From aa33989952c0e0014a6038b7f40f083ece203b45 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 22 Feb 2023 12:02:32 +0200 Subject: [PATCH 4/4] Improve target user detection for ws emitter --- .../loc.api/ws-transport/ws.event.emitter.js | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/workers/loc.api/ws-transport/ws.event.emitter.js b/workers/loc.api/ws-transport/ws.event.emitter.js index 5fdecd02f..e249f6e4e 100644 --- a/workers/loc.api/ws-transport/ws.event.emitter.js +++ b/workers/loc.api/ws-transport/ws.event.emitter.js @@ -26,10 +26,13 @@ class WSEventEmitter extends AbstractWSEventEmitter { ) } - isInvalidAuth (auth = {}, { _id, email } = {}) { + isNotTargetUser (auth = {}, user = {}) { + // For the sync process user id need to take from the session object + const _id = auth?._id ?? auth?.session?._id + return ( - auth._id !== _id || - auth.email !== email + !Number.isInteger(_id) || + user?._id !== _id ) } @@ -56,10 +59,7 @@ class WSEventEmitter extends AbstractWSEventEmitter { auth = {} ) { return this.emitSyncingStep(async (user, ...args) => { - if ( - !Number.isInteger(auth?._id) || - user?._id !== auth?._id - ) { + if (this.isNotTargetUser(auth, user)) { return { isNotEmitted: true } } @@ -74,10 +74,7 @@ class WSEventEmitter extends AbstractWSEventEmitter { auth = {} ) { return this.emit(async (user, ...args) => { - if ( - !Number.isInteger(auth?._id) || - user?._id !== auth?._id - ) { + if (this.isNotTargetUser(auth, user)) { return { isNotEmitted: true } } @@ -92,13 +89,7 @@ class WSEventEmitter extends AbstractWSEventEmitter { auth = {} ) { return this.emit(async (user, ...args) => { - // For the sync process user id need to take from the session object - const id = auth?._id ?? auth?.session?._id - - if ( - !Number.isInteger(id) || - user?._id !== id - ) { + if (this.isNotTargetUser(auth, user)) { return { isNotEmitted: true } }