From 1a062a8adf7c509a3557c0fa0329fa1f077d7b62 Mon Sep 17 00:00:00 2001 From: Joao Date: Wed, 4 Dec 2024 13:39:13 -0400 Subject: [PATCH 1/8] add failing test covering the bug --- app/api/csv/specs/csvLoader.spec.js | 45 +++++++++++++++++++++++++- app/api/csv/specs/csvLoaderFixtures.ts | 21 +++++++++++- app/api/csv/specs/simple_template.csv | 2 ++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 app/api/csv/specs/simple_template.csv diff --git a/app/api/csv/specs/csvLoader.spec.js b/app/api/csv/specs/csvLoader.spec.js index 7742e94ce3..9e39bac094 100644 --- a/app/api/csv/specs/csvLoader.spec.js +++ b/app/api/csv/specs/csvLoader.spec.js @@ -1,13 +1,15 @@ +/* eslint-disable max-statements */ /* eslint-disable max-lines */ import path from 'path'; import { CSVLoader } from 'api/csv'; -import { templateWithGeneratedTitle } from 'api/csv/specs/csvLoaderFixtures'; +import { simpleTemplateId, templateWithGeneratedTitle } from 'api/csv/specs/csvLoaderFixtures'; import entities from 'api/entities'; import translations from 'api/i18n'; import { search } from 'api/search'; import settings from 'api/settings'; import db from 'api/utils/testing_db'; +import moment from 'moment'; import typeParsers from '../typeParsers'; import fixtures, { template1Id } from './csvLoaderFixtures'; import { mockCsvFileReadStream } from './helpers'; @@ -400,4 +402,45 @@ describe('csvLoader', () => { }); }); }); + + test('given the user has english and spanish languages installed and imported a csv with metadata in both versions, it should import translated version correctly', async () => { + jest.restoreAllMocks(); + const _fixtures = { ...fixtures }; + const dateFormat = 'MM/dd/yyyy'; + const _settings = { + ..._fixtures.settings[0], + languages: [ + { key: 'en', label: 'English', default: true }, + { key: 'es', label: 'Spanish' }, + { key: 'fr', label: 'French' }, + ], + newNameGeneration: true, + dateFormat, + }; + _fixtures.settings = [_settings]; + await db.setupFixturesAndContext(_fixtures); + const csv = path.join(__dirname, '/simple_template.csv'); + const selectedLanguageOnUserInterface = 'es'; + + await loader.load(csv, simpleTemplateId, { language: selectedLanguageOnUserInterface }); + + const [englishEntity] = await entities.get({ language: 'en' }); + const [spanishEntity] = await entities.get({ language: 'es' }); + const [frenchEntity] = await entities.get({ language: 'fr' }); + + expect(spanishEntity.metadata).toEqual({ + simple_text_field: [{ value: 'Spanish' }], + date_field: [{ value: moment.utc('12/01/2024', [dateFormat.toUpperCase()]).unix() }], + }); + + expect(englishEntity.metadata).toEqual({ + simple_text_field: [{ value: 'English' }], + date_field: [{ value: moment.utc('12/01/2024', [dateFormat.toUpperCase()]).unix() }], + }); + + expect(frenchEntity.metadata).toEqual({ + simple_text_field: [{ value: 'French' }], + date_field: [{ value: moment.utc('12/01/2024', [dateFormat.toUpperCase()]).unix() }], + }); + }); }); diff --git a/app/api/csv/specs/csvLoaderFixtures.ts b/app/api/csv/specs/csvLoaderFixtures.ts index 3cf4d2a95e..536e3290eb 100644 --- a/app/api/csv/specs/csvLoaderFixtures.ts +++ b/app/api/csv/specs/csvLoaderFixtures.ts @@ -6,6 +6,7 @@ import { TranslationDBO } from 'api/i18n.v2/schemas/TranslationDBO'; import { getFixturesFactory } from 'api/utils/fixturesFactory'; const template1Id = db.id(); +const simpleTemplateId = db.id(); const multiSelectThesaurusId = db.id(); const thesauri1Id = db.id(); const templateToRelateId = db.id(); @@ -48,6 +49,24 @@ const commonTranslationsV2 = (language: LanguageISO6391): TranslationDBO[] => [ export default { templates: [ + { + _id: simpleTemplateId, + name: 'Simple template', + properties: [ + { + _id: db.id(), + type: propertyTypes.text, + label: 'simple text field', + name: templateUtils.safeName('simple text field'), + }, + { + _id: db.id(), + type: propertyTypes.date, + label: 'Date field', + name: templateUtils.safeName('Date field'), + }, + ], + }, { _id: templateToRelateId, name: 'template to relate', @@ -180,4 +199,4 @@ export default { ], }; -export { template1Id, templateWithGeneratedTitle, thesauri1Id }; +export { template1Id, templateWithGeneratedTitle, thesauri1Id, simpleTemplateId }; diff --git a/app/api/csv/specs/simple_template.csv b/app/api/csv/specs/simple_template.csv new file mode 100644 index 0000000000..67171fe92f --- /dev/null +++ b/app/api/csv/specs/simple_template.csv @@ -0,0 +1,2 @@ +Title,Date field,simple text field__en,simple text field__es,simple text field__fr +Simple template title,12/01/2024,English,Spanish,French \ No newline at end of file From 15667c1f81715c574d578977f48813e65b69182a Mon Sep 17 00:00:00 2001 From: Joao Date: Wed, 4 Dec 2024 13:39:30 -0400 Subject: [PATCH 2/8] fix date format on import csv --- app/api/csv/csvLoader.ts | 3 ++- app/api/csv/importEntity.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/api/csv/csvLoader.ts b/app/api/csv/csvLoader.ts index 70282978cb..4d0b9ae062 100644 --- a/app/api/csv/csvLoader.ts +++ b/app/api/csv/csvLoader.ts @@ -132,7 +132,8 @@ export class CSVLoader extends EventEmitter { template, file, propNameToThesauriId, - indexedTranslations + indexedTranslations, + dateFormat ); this.emit('entityLoaded', entity); } diff --git a/app/api/csv/importEntity.ts b/app/api/csv/importEntity.ts index d6cdea4966..a72d8b99fc 100644 --- a/app/api/csv/importEntity.ts +++ b/app/api/csv/importEntity.ts @@ -174,7 +174,8 @@ const translateEntity = async ( template: TemplateSchema, importFile: ImportFile, propNameToThesauriId: Record, - indexedTranslations: FullyIndexedTranslations + indexedTranslations: FullyIndexedTranslations, + dateFormat?: string ) => { await entitiesModel.saveMultiple( await Promise.all( @@ -190,6 +191,7 @@ const translateEntity = async ( template, { language: translatedEntity.language, + dateFormat, } ); From c0c0986487bfef106559ec79fa1aff27fb83b139 Mon Sep 17 00:00:00 2001 From: Joao Date: Wed, 4 Dec 2024 13:45:37 -0400 Subject: [PATCH 3/8] update test title --- app/api/csv/specs/csvLoader.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/csv/specs/csvLoader.spec.js b/app/api/csv/specs/csvLoader.spec.js index 9e39bac094..64ea049ccd 100644 --- a/app/api/csv/specs/csvLoader.spec.js +++ b/app/api/csv/specs/csvLoader.spec.js @@ -403,7 +403,7 @@ describe('csvLoader', () => { }); }); - test('given the user has english and spanish languages installed and imported a csv with metadata in both versions, it should import translated version correctly', async () => { + test('given the user has english, spanish and french languages installed and imported a csv with metadata in both versions, it should import translated version correctly', async () => { jest.restoreAllMocks(); const _fixtures = { ...fixtures }; const dateFormat = 'MM/dd/yyyy'; From 87b560d9bd421b4d79754d844c5a8758fb45a17f Mon Sep 17 00:00:00 2001 From: Joao Date: Mon, 9 Dec 2024 14:51:53 -0400 Subject: [PATCH 4/8] improve testing --- app/api/csv/specs/csvLoader.spec.js | 76 +++++++++++++++---------- app/api/csv/specs/simple_template.csv | 4 +- app/api/csv/specs/simple_template_2.csv | 2 + 3 files changed, 49 insertions(+), 33 deletions(-) create mode 100644 app/api/csv/specs/simple_template_2.csv diff --git a/app/api/csv/specs/csvLoader.spec.js b/app/api/csv/specs/csvLoader.spec.js index 64ea049ccd..4007ea71af 100644 --- a/app/api/csv/specs/csvLoader.spec.js +++ b/app/api/csv/specs/csvLoader.spec.js @@ -403,44 +403,58 @@ describe('csvLoader', () => { }); }); - test('given the user has english, spanish and french languages installed and imported a csv with metadata in both versions, it should import translated version correctly', async () => { - jest.restoreAllMocks(); - const _fixtures = { ...fixtures }; - const dateFormat = 'MM/dd/yyyy'; - const _settings = { - ..._fixtures.settings[0], - languages: [ - { key: 'en', label: 'English', default: true }, - { key: 'es', label: 'Spanish' }, - { key: 'fr', label: 'French' }, - ], - newNameGeneration: true, - dateFormat, + describe('should parse date respecting the dateFormat on settings collection ', () => { + beforeEach(() => jest.restoreAllMocks()); + + const setDateFormat = async dateFormat => { + const _fixtures = { ...fixtures }; + _fixtures.settings = [ + { + ..._fixtures.settings[0], + languages: [ + { key: 'en', label: 'English', default: true }, + { key: 'es', label: 'Spanish' }, + ], + dateFormat, + }, + ]; + await db.setupFixturesAndContext(_fixtures); }; - _fixtures.settings = [_settings]; - await db.setupFixturesAndContext(_fixtures); - const csv = path.join(__dirname, '/simple_template.csv'); - const selectedLanguageOnUserInterface = 'es'; - await loader.load(csv, simpleTemplateId, { language: selectedLanguageOnUserInterface }); + it('should correctly parse MM/dd/yyyy', async () => { + const dateFormat = 'MM/dd/yyyy'; + await setDateFormat(dateFormat); - const [englishEntity] = await entities.get({ language: 'en' }); - const [spanishEntity] = await entities.get({ language: 'es' }); - const [frenchEntity] = await entities.get({ language: 'fr' }); + const dateOnCSV = '12/31/2024'; + const csv = path.join(__dirname, '/simple_template.csv'); + const selectedLanguageOnUserInterface = 'es'; + const expectedDate = moment.utc(dateOnCSV, [dateFormat.toUpperCase()]).unix(); - expect(spanishEntity.metadata).toEqual({ - simple_text_field: [{ value: 'Spanish' }], - date_field: [{ value: moment.utc('12/01/2024', [dateFormat.toUpperCase()]).unix() }], - }); + await loader.load(csv, simpleTemplateId, { language: selectedLanguageOnUserInterface }); + + const [englishEntity] = await entities.get({ language: 'en' }); + const [spanishEntity] = await entities.get({ language: 'es' }); - expect(englishEntity.metadata).toEqual({ - simple_text_field: [{ value: 'English' }], - date_field: [{ value: moment.utc('12/01/2024', [dateFormat.toUpperCase()]).unix() }], + expect(spanishEntity.metadata.date_field).toEqual([{ value: expectedDate }]); + expect(englishEntity.metadata.date_field).toEqual([{ value: expectedDate }]); }); - expect(frenchEntity.metadata).toEqual({ - simple_text_field: [{ value: 'French' }], - date_field: [{ value: moment.utc('12/01/2024', [dateFormat.toUpperCase()]).unix() }], + it('should correctly parse yyyy/MM/dd', async () => { + const dateFormat = 'yyyy/MM/dd'; + await setDateFormat(dateFormat); + + const dateOnCSV = '2024/12/31'; + const csv = path.join(__dirname, '/simple_template_2.csv'); + const selectedLanguageOnUserInterface = 'es'; + const expectedDate = moment.utc(dateOnCSV, [dateFormat.toUpperCase()]).unix(); + + await loader.load(csv, simpleTemplateId, { language: selectedLanguageOnUserInterface }); + + const [englishEntity] = await entities.get({ language: 'en' }); + const [spanishEntity] = await entities.get({ language: 'es' }); + + expect(spanishEntity.metadata.date_field).toEqual([{ value: expectedDate }]); + expect(englishEntity.metadata.date_field).toEqual([{ value: expectedDate }]); }); }); }); diff --git a/app/api/csv/specs/simple_template.csv b/app/api/csv/specs/simple_template.csv index 67171fe92f..16fc956bdc 100644 --- a/app/api/csv/specs/simple_template.csv +++ b/app/api/csv/specs/simple_template.csv @@ -1,2 +1,2 @@ -Title,Date field,simple text field__en,simple text field__es,simple text field__fr -Simple template title,12/01/2024,English,Spanish,French \ No newline at end of file +Title,Date field,simple text field__en,simple text field__es +Simple template title,12/31/2024,English,Spanish \ No newline at end of file diff --git a/app/api/csv/specs/simple_template_2.csv b/app/api/csv/specs/simple_template_2.csv new file mode 100644 index 0000000000..8e9f8ba623 --- /dev/null +++ b/app/api/csv/specs/simple_template_2.csv @@ -0,0 +1,2 @@ +Title,Date field,simple text field__en,simple text field__es +Simple template title,2024/12/31,English,Spanish \ No newline at end of file From efc5f1c4738b4b2c7892ec34fc6ebb8ce671158c Mon Sep 17 00:00:00 2001 From: Daneryl Date: Mon, 16 Dec 2024 10:45:35 +0100 Subject: [PATCH 5/8] Testing the queue.v2 --- app/api/queue.v2/configuration/factories.ts | 4 ++-- app/queueRegistry.ts | 20 +++++++++++++++++- scripts/scripts.v2/dispatchTestJobs.ts | 23 +++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 scripts/scripts.v2/dispatchTestJobs.ts diff --git a/app/api/queue.v2/configuration/factories.ts b/app/api/queue.v2/configuration/factories.ts index b356f33642..a6712e5ee5 100644 --- a/app/api/queue.v2/configuration/factories.ts +++ b/app/api/queue.v2/configuration/factories.ts @@ -5,7 +5,7 @@ import { getSharedClient, getSharedConnection, } from 'api/common.v2/database/getConnectionForCurrentTenant'; -import { DefaultLogger } from 'api/log.v2/infrastructure/StandardLogger'; +import { DefaultLogger, SystemLogger } from 'api/log.v2/infrastructure/StandardLogger'; import { JobsRouter } from '../infrastructure/JobsRouter'; import { MongoQueueAdapter } from '../infrastructure/MongoQueueAdapter'; import { NamespacedDispatcher } from '../infrastructure/NamespacedDispatcher'; @@ -13,7 +13,7 @@ import { NamespacedDispatcher } from '../infrastructure/NamespacedDispatcher'; export function DefaultQueueAdapter() { return new MongoQueueAdapter( getSharedConnection(), - new MongoTransactionManager(getSharedClient(), DefaultLogger()) + new MongoTransactionManager(getSharedClient(), SystemLogger()) ); } diff --git a/app/queueRegistry.ts b/app/queueRegistry.ts index c25931535b..fe4fab9aa6 100644 --- a/app/queueRegistry.ts +++ b/app/queueRegistry.ts @@ -1,4 +1,4 @@ -import { Dispatchable } from 'api/queue.v2/application/contracts/Dispatchable'; +import { Dispatchable, HeartbeatCallback } from 'api/queue.v2/application/contracts/Dispatchable'; import { DispatchableClass } from 'api/queue.v2/application/contracts/JobsDispatcher'; import { UpdateTemplateRelationshipPropertiesJob as createUpdateTemplateRelationshipPropertiesJob, @@ -7,6 +7,23 @@ import { import { UpdateRelationshipPropertiesJob } from 'api/relationships.v2/services/propertyUpdateStrategies/UpdateRelationshipPropertiesJob'; import { UpdateTemplateRelationshipPropertiesJob } from 'api/relationships.v2/services/propertyUpdateStrategies/UpdateTemplateRelationshipPropertiesJob'; +function randomIntFromInterval(min, max) { + // min and max included + return Math.floor(Math.random() * (max - min + 1) + min); +} + +export class TestJob implements Dispatchable { + static BATCH_SIZE = 200; + + constructor() {} + + async handleDispatch(_heartbeat: HeartbeatCallback) { + await new Promise(resolve => { + setTimeout(resolve, randomIntFromInterval(1000, 2000)); + }); + } +} + export function registerJobs( register: ( dispatchable: DispatchableClass, @@ -15,4 +32,5 @@ export function registerJobs( ) { register(UpdateRelationshipPropertiesJob, async () => createUpdateRelationshipPropertiesJob()); register(UpdateTemplateRelationshipPropertiesJob, createUpdateTemplateRelationshipPropertiesJob); + register(TestJob, async () => new TestJob()); } diff --git a/scripts/scripts.v2/dispatchTestJobs.ts b/scripts/scripts.v2/dispatchTestJobs.ts new file mode 100644 index 0000000000..2dd030f6fd --- /dev/null +++ b/scripts/scripts.v2/dispatchTestJobs.ts @@ -0,0 +1,23 @@ +import { DefaultDispatcher } from 'api/queue.v2/configuration/factories'; +import { TestJob } from '../../app/queueRegistry'; +import { DB } from 'api/odm'; +import { config } from 'api/config'; + +let dbAuth = {}; + +if (process.env.DBUSER) { + dbAuth = { + auth: { authSource: 'admin' }, + user: process.env.DBUSER, + pass: process.env.DBPASS, + }; +} + +(async () => { + await DB.connect(config.DBHOST, dbAuth); + const dispatcher = await DefaultDispatcher('default'); + for (let i = 0; i < 100; i++) { + await dispatcher.dispatch(TestJob, {}); + } + await DB.disconnect(); +})(); From e71a2a114488a60419c763bdba7d91f9f008a7a2 Mon Sep 17 00:00:00 2001 From: Joao Date: Mon, 16 Dec 2024 07:17:35 -0400 Subject: [PATCH 6/8] fix import entities with relationships --- app/api/csv/importEntity.ts | 54 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/app/api/csv/importEntity.ts b/app/api/csv/importEntity.ts index a72d8b99fc..1d38e345d7 100644 --- a/app/api/csv/importEntity.ts +++ b/app/api/csv/importEntity.ts @@ -1,8 +1,10 @@ +/* eslint-disable no-await-in-loop */ +/* eslint-disable no-unreachable-loop */ +/* eslint-disable no-restricted-syntax */ // eslint-disable-next-line node/no-restricted-import import { createReadStream } from 'fs'; import entities from 'api/entities'; import { search } from 'api/search'; -import entitiesModel from 'api/entities/entitiesModel'; import { processDocument } from 'api/files/processDocument'; import { RawEntity } from 'api/csv/entityRow'; import { TemplateSchema } from 'shared/types/templateType'; @@ -177,33 +179,31 @@ const translateEntity = async ( indexedTranslations: FullyIndexedTranslations, dateFormat?: string ) => { - await entitiesModel.saveMultiple( - await Promise.all( - translations.map(async translatedEntity => { - const translatedEntityObject = await entityObject( - { - ...translatedEntity, - propertiesFromColumns: { - ...translatedEntity.propertiesFromColumns, - id: ensure(entity.sharedId), - }, - }, - template, - { - language: translatedEntity.language, - dateFormat, - } - ); + for (const translatedEntity of translations) { + const entityParsed = await entityObject( + { + ...translatedEntity, + propertiesFromColumns: { + ...translatedEntity.propertiesFromColumns, + id: ensure(entity.sharedId), + }, + }, + template, + { + language: translatedEntity.language, + dateFormat, + } + ); - return translateSelectLabels( - translatedEntityObject, - translatedEntity.language, - indexedTranslations, - propNameToThesauriId - ); - }) - ) - ); + const toSave = translateSelectLabels( + entityParsed, + translatedEntity.language, + indexedTranslations, + propNameToThesauriId + ); + + await entities.save(toSave, { language: translatedEntity.language, user: {} }); + } await Promise.all( translations.map(async translatedEntity => { From 21c508326f1582a192f4de312370c8d8892801f1 Mon Sep 17 00:00:00 2001 From: Joao Date: Mon, 16 Dec 2024 10:15:03 -0400 Subject: [PATCH 7/8] fix eslint issues --- app/api/csv/importEntity.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/api/csv/importEntity.ts b/app/api/csv/importEntity.ts index 1d38e345d7..428789eb05 100644 --- a/app/api/csv/importEntity.ts +++ b/app/api/csv/importEntity.ts @@ -1,6 +1,3 @@ -/* eslint-disable no-await-in-loop */ -/* eslint-disable no-unreachable-loop */ -/* eslint-disable no-restricted-syntax */ // eslint-disable-next-line node/no-restricted-import import { createReadStream } from 'fs'; import entities from 'api/entities'; @@ -179,31 +176,33 @@ const translateEntity = async ( indexedTranslations: FullyIndexedTranslations, dateFormat?: string ) => { - for (const translatedEntity of translations) { + await translations.reduce(async (prevPromise, translation) => { + await prevPromise; + const entityParsed = await entityObject( { - ...translatedEntity, + ...translation, propertiesFromColumns: { - ...translatedEntity.propertiesFromColumns, + ...translation.propertiesFromColumns, id: ensure(entity.sharedId), }, }, template, { - language: translatedEntity.language, + language: translation.language, dateFormat, } ); const toSave = translateSelectLabels( entityParsed, - translatedEntity.language, + translation.language, indexedTranslations, propNameToThesauriId ); - await entities.save(toSave, { language: translatedEntity.language, user: {} }); - } + await entities.save(toSave, { language: translation.language, user: {} }); + }, Promise.resolve()); await Promise.all( translations.map(async translatedEntity => { From 1db55a48c6b6c8f5b4a23248d5d2ca272843ec7f Mon Sep 17 00:00:00 2001 From: Joao Date: Mon, 16 Dec 2024 10:29:19 -0400 Subject: [PATCH 8/8] Revert "Testing the queue.v2" This reverts commit efc5f1c4738b4b2c7892ec34fc6ebb8ce671158c. --- app/api/queue.v2/configuration/factories.ts | 4 ++-- app/queueRegistry.ts | 20 +----------------- scripts/scripts.v2/dispatchTestJobs.ts | 23 --------------------- 3 files changed, 3 insertions(+), 44 deletions(-) delete mode 100644 scripts/scripts.v2/dispatchTestJobs.ts diff --git a/app/api/queue.v2/configuration/factories.ts b/app/api/queue.v2/configuration/factories.ts index a6712e5ee5..b356f33642 100644 --- a/app/api/queue.v2/configuration/factories.ts +++ b/app/api/queue.v2/configuration/factories.ts @@ -5,7 +5,7 @@ import { getSharedClient, getSharedConnection, } from 'api/common.v2/database/getConnectionForCurrentTenant'; -import { DefaultLogger, SystemLogger } from 'api/log.v2/infrastructure/StandardLogger'; +import { DefaultLogger } from 'api/log.v2/infrastructure/StandardLogger'; import { JobsRouter } from '../infrastructure/JobsRouter'; import { MongoQueueAdapter } from '../infrastructure/MongoQueueAdapter'; import { NamespacedDispatcher } from '../infrastructure/NamespacedDispatcher'; @@ -13,7 +13,7 @@ import { NamespacedDispatcher } from '../infrastructure/NamespacedDispatcher'; export function DefaultQueueAdapter() { return new MongoQueueAdapter( getSharedConnection(), - new MongoTransactionManager(getSharedClient(), SystemLogger()) + new MongoTransactionManager(getSharedClient(), DefaultLogger()) ); } diff --git a/app/queueRegistry.ts b/app/queueRegistry.ts index fe4fab9aa6..c25931535b 100644 --- a/app/queueRegistry.ts +++ b/app/queueRegistry.ts @@ -1,4 +1,4 @@ -import { Dispatchable, HeartbeatCallback } from 'api/queue.v2/application/contracts/Dispatchable'; +import { Dispatchable } from 'api/queue.v2/application/contracts/Dispatchable'; import { DispatchableClass } from 'api/queue.v2/application/contracts/JobsDispatcher'; import { UpdateTemplateRelationshipPropertiesJob as createUpdateTemplateRelationshipPropertiesJob, @@ -7,23 +7,6 @@ import { import { UpdateRelationshipPropertiesJob } from 'api/relationships.v2/services/propertyUpdateStrategies/UpdateRelationshipPropertiesJob'; import { UpdateTemplateRelationshipPropertiesJob } from 'api/relationships.v2/services/propertyUpdateStrategies/UpdateTemplateRelationshipPropertiesJob'; -function randomIntFromInterval(min, max) { - // min and max included - return Math.floor(Math.random() * (max - min + 1) + min); -} - -export class TestJob implements Dispatchable { - static BATCH_SIZE = 200; - - constructor() {} - - async handleDispatch(_heartbeat: HeartbeatCallback) { - await new Promise(resolve => { - setTimeout(resolve, randomIntFromInterval(1000, 2000)); - }); - } -} - export function registerJobs( register: ( dispatchable: DispatchableClass, @@ -32,5 +15,4 @@ export function registerJobs( ) { register(UpdateRelationshipPropertiesJob, async () => createUpdateRelationshipPropertiesJob()); register(UpdateTemplateRelationshipPropertiesJob, createUpdateTemplateRelationshipPropertiesJob); - register(TestJob, async () => new TestJob()); } diff --git a/scripts/scripts.v2/dispatchTestJobs.ts b/scripts/scripts.v2/dispatchTestJobs.ts deleted file mode 100644 index 2dd030f6fd..0000000000 --- a/scripts/scripts.v2/dispatchTestJobs.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { DefaultDispatcher } from 'api/queue.v2/configuration/factories'; -import { TestJob } from '../../app/queueRegistry'; -import { DB } from 'api/odm'; -import { config } from 'api/config'; - -let dbAuth = {}; - -if (process.env.DBUSER) { - dbAuth = { - auth: { authSource: 'admin' }, - user: process.env.DBUSER, - pass: process.env.DBPASS, - }; -} - -(async () => { - await DB.connect(config.DBHOST, dbAuth); - const dispatcher = await DefaultDispatcher('default'); - for (let i = 0; i < 100; i++) { - await dispatcher.dispatch(TestJob, {}); - } - await DB.disconnect(); -})();