Skip to content

Commit bdfe10f

Browse files
authored
Merge pull request #519 from ZIMkaRU/refactoring/dedicate-separate-file-for-report-queue-event-names
Dedicate separate file for report queue event names
2 parents 62a0b2e + 7d65c98 commit bdfe10f

4 files changed

Lines changed: 23 additions & 11 deletions

File tree

workers/api.framework.report.wrk.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ const {
3939
PDFBufferUnderElectronCreationError,
4040
PDFBufferUnderFrameworkCreationError
4141
} = require('@bitfinex/bfx-report/workers/loc.api/errors')
42+
const QUEUE_EVENT_NAMES = require(
43+
'@bitfinex/bfx-report/workers/loc.api/queue/queue.event.names'
44+
)
4245

4346
const appDeps = require('./loc.api/di/app.deps')
4447
const TYPES = require('./loc.api/di/types')
@@ -208,7 +211,7 @@ class WrkReportFrameWorkApi extends WrkReportServiceApi {
208211

209212
await wsTransport.start()
210213

211-
processorQueue.on('error:base', (err, job) => {
214+
processorQueue.on(QUEUE_EVENT_NAMES.ERROR_BASE, (err, job) => {
212215
if (
213216
!(err instanceof PDFBufferUnderElectronCreationError) &&
214217
!(err instanceof PDFBufferUnderFrameworkCreationError)
@@ -223,7 +226,7 @@ class WrkReportFrameWorkApi extends WrkReportServiceApi {
223226
this.logger.error(`WS_EVENT_EMITTER:REPORT_FILE_FAILED: ${err.stack || err}`)
224227
})
225228
})
226-
aggregatorQueue.on('completed', (res) => {
229+
aggregatorQueue.on(QUEUE_EVENT_NAMES.COMPLETED, (res) => {
227230
const {
228231
reportFilesMetadata,
229232
csvFilesMetadata, // For compatibility with old implementation

workers/loc.api/generate-report-file/csv-writer/full-snapshot-report-csv-writer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const {
99
const {
1010
omitExtraParamFieldsForReportExport
1111
} = require('@bitfinex/bfx-report/workers/loc.api/generate-report-file/helpers')
12+
const QUEUE_EVENT_NAMES = require(
13+
'@bitfinex/bfx-report/workers/loc.api/queue/queue.event.names'
14+
)
1215

1316
module.exports = (
1417
rService,
@@ -29,7 +32,7 @@ module.exports = (
2932
...args?.params
3033
}
3134

32-
queue.emit('progress', 0)
35+
queue.emit(QUEUE_EVENT_NAMES.PROGRESS, 0)
3336

3437
if (typeof jobData === 'string') {
3538
await streamWriter(
@@ -40,7 +43,7 @@ module.exports = (
4043
}]
4144
)
4245

43-
queue.emit('progress', 100)
46+
queue.emit(QUEUE_EVENT_NAMES.PROGRESS, 100)
4447

4548
return
4649
}
@@ -173,5 +176,5 @@ module.exports = (
173176
]
174177
)
175178

176-
queue.emit('progress', 100)
179+
queue.emit(QUEUE_EVENT_NAMES.PROGRESS, 100)
177180
}

workers/loc.api/generate-report-file/csv-writer/full-tax-report-csv-writer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const {
99
const {
1010
omitExtraParamFieldsForReportExport
1111
} = require('@bitfinex/bfx-report/workers/loc.api/generate-report-file/helpers')
12+
const QUEUE_EVENT_NAMES = require(
13+
'@bitfinex/bfx-report/workers/loc.api/queue/queue.event.names'
14+
)
1215

1316
module.exports = (
1417
rService,
@@ -30,7 +33,7 @@ module.exports = (
3033
...args?.params
3134
}
3235

33-
queue.emit('progress', 0)
36+
queue.emit(QUEUE_EVENT_NAMES.PROGRESS, 0)
3437

3538
if (typeof jobData === 'string') {
3639
await streamWriter(
@@ -41,7 +44,7 @@ module.exports = (
4144
}]
4245
)
4346

44-
queue.emit('progress', 100)
47+
queue.emit(QUEUE_EVENT_NAMES.PROGRESS, 100)
4548

4649
return
4750
}
@@ -206,5 +209,5 @@ module.exports = (
206209
]
207210
)
208211

209-
queue.emit('progress', 100)
212+
queue.emit(QUEUE_EVENT_NAMES.PROGRESS, 100)
210213
}

workers/loc.api/generate-report-file/csv-writer/transaction-tax-report-csv-writer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const TRANSLATION_NAMESPACES = require(
1212
const {
1313
omitExtraParamFieldsForReportExport
1414
} = require('@bitfinex/bfx-report/workers/loc.api/generate-report-file/helpers')
15+
const QUEUE_EVENT_NAMES = require(
16+
'@bitfinex/bfx-report/workers/loc.api/queue/queue.event.names'
17+
)
1518

1619
module.exports = (
1720
rService,
@@ -35,7 +38,7 @@ module.exports = (
3538
}
3639
const { language } = params ??
3740

38-
queue.emit('progress', 0)
41+
queue.emit(QUEUE_EVENT_NAMES.PROGRESS, 0)
3942

4043
if (typeof jobData === 'string') {
4144
await streamWriter(
@@ -46,7 +49,7 @@ module.exports = (
4649
}]
4750
)
4851

49-
queue.emit('progress', 100)
52+
queue.emit(QUEUE_EVENT_NAMES.PROGRESS, 100)
5053

5154
return
5255
}
@@ -108,5 +111,5 @@ ${i18next.t('template.delistedCcyMessageEnd', transOpts)}\
108111
csvStreamDataMap
109112
)
110113

111-
queue.emit('progress', 100)
114+
queue.emit(QUEUE_EVENT_NAMES.PROGRESS, 100)
112115
}

0 commit comments

Comments
 (0)