Skip to content

Commit

Permalink
Configure batch size for the Monalisa sync (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
xsalonx authored Jun 15, 2023
1 parent 7b7a480 commit ba9b889
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = Object.freeze({
// App config
winston: ResProvider.winston(),
database: ResProvider.database(),
syncTaskAtStart: process.env['RCT_SYNC_TASK_AT_START']?.trim().toLowerCase() === 'true' ? process.env['RCT_SYNC_TASK_AT_START'] : false,
syncTaskAtStart: ResProvider.envOrDef('RCT_SYNC_TASK_AT_START', false, Boolean),
databasePersistance: require('./databasePersistance.js'),
public: require('./public.js'),

Expand All @@ -38,5 +38,5 @@ module.exports = Object.freeze({
stack: (logger, er) => logger.error(er.stack),
object: (logger, er) => logger.error(JSON.stringify(er, null, 2)),
},
defaultErrorsLogginDepth: process.env['RCT_ERR_DEPTH']?.length() > 0 ? process.env['RCT_ERR_DEPTH'] : 'object',
defaultErrorsLogginDepth: ResProvider.envOrDef('RCT_ERR_DEPTH', 'object'),
});
4 changes: 4 additions & 0 deletions app/config/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const services = {
mcDetTag: ResProvider.getServiceEndpoint('ML_MC_TAG'),
},
},

batchSize: {
ML: ResProvider.envOrDef('RCT_ML_BATCH_SIZE', 2),
},
};

/*
Expand Down
7 changes: 7 additions & 0 deletions app/lib/ResProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class ResProvider {
return res;
}

static envOrDef(name, def, castType = String) {
if (castType == Boolean) {
return process.env[name]?.length > 0 ? Boolean(process.env[name] == 'true') : def;
}
return process.env[name]?.length > 0 ? castType(process.env[name]) : def;
}

static areDesiredValuesPresent(obj, objDefinition) {
for (const key of Object.values(objDefinition)) {
if (!obj[key]) {
Expand Down
1 change: 1 addition & 0 deletions app/lib/alimonitor-services/AbstractServiceSynchronizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class AbstractServiceSynchronizer {
} else {
await this.makeSequentialRequest(data);
}

this.monitor.logResults();
} catch (fatalError) {
this.logger.error(fatalError.stack);
Expand Down
2 changes: 0 additions & 2 deletions app/lib/alimonitor-services/BookkeepingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ const EndpintFormatter = require('./ServicesEndpointsFormatter.js');
class BookkeepingService extends AbstractServiceSynchronizer {
constructor() {
super();
this.batchedRequestes = true;
this.batchSize = 100;
this.omitWhenCached = false;

this.ketpFields = {
id: 'ali-bk-id',
Expand Down
6 changes: 1 addition & 5 deletions app/lib/alimonitor-services/MonalisaService.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ const config = require('../config/configProvider.js');
class MonalisaService extends AbstractServiceSynchronizer {
constructor() {
super();
this.batchedRequestes = true;
this.batchSize = 5;
this.omitWhenCached = false;
this.batchSize = config.services.batchSize.ML;

this.ketpFields = {
name: 'name',
Expand Down Expand Up @@ -92,8 +90,6 @@ class MonalisaService extends AbstractServiceSynchronizer {
const q1 = await dbClient.query(pgCommand);
const q2 = await this.monalisaServiceDetails.sync(d);
return Promise.all([q1, q2]);
// eslint-disable-next-line capitalized-comments
// return await Promise.all([dbClient.query(pgCommand), this.monalisaServiceDetails.sync(d)]);
}

extractPeriod(rowData) {
Expand Down
2 changes: 0 additions & 2 deletions app/lib/alimonitor-services/MonalisaServiceDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const EndpointsFormatter = require('./ServicesEndpointsFormatter.js');
class MonalisaServiceDetails extends AbstractServiceSynchronizer {
constructor() {
super();
this.batchedRequestes = true;
this.batchSize = 5;
this.omitWhenCached = false;

this.ketpFields = {
run_no: 'run_number',
Expand Down
3 changes: 1 addition & 2 deletions app/lib/alimonitor-services/MonalisaServiceMC.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class MonalisaServiceMC extends AbstractServiceSynchronizer {
constructor() {
super();

this.batchedRequestes = true;
this.batchSize = 5;
this.batchSize = config.services.batchSize.ML;

this.ketpFields = {
name: 'name',
Expand Down
1 change: 0 additions & 1 deletion app/lib/alimonitor-services/MonalisaServiceMCDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class MonalisaServiceMCDetails extends AbstractServiceSynchronizer {
constructor() {
super();

this.batchedRequestes = true;
this.batchSize = 5;

this.keptFields = {
Expand Down

0 comments on commit ba9b889

Please sign in to comment.