Skip to content

Commit

Permalink
[O2B-1417] Add more logs to services synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboulais committed Dec 13, 2024
1 parent 5dafb0e commit 6eaf6bf
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
10 changes: 2 additions & 8 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,9 @@ class BookkeepingApplication {
const ccdbSynchronizer = new CcdbSynchronizer(ccdbConfig.runInfoUrl);
this.scheduledProcessesManager.schedule(
// Sync runs a few sync period ago in case some synchronization failed
async () => {
try {
await ccdbSynchronizer.syncFirstAndLastTf(new Date(Date.now() - ccdbConfig.synchronizationPeriod * 5));
} catch (e) {
this._logger.errorMessage(`Failed to synchronize runs first and last TF:\n ${e.stack}`);
}
},
() => ccdbSynchronizer.syncFirstAndLastTf(new Date(Date.now() - ccdbConfig.synchronizationPeriod * 5)),

Check warning on line 96 in lib/application.js

View check run for this annotation

Codecov / codecov/patch

lib/application.js#L96

Added line #L96 was not covered by tests
{
wait: 3 * 1000,
wait: 10 * 1000,
every: ccdbConfig.synchronizationPeriod,
},
);
Expand Down
2 changes: 1 addition & 1 deletion lib/config/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ exports.services = {

ccdb: {
enableSynchronization: CCDB_ENABLE_SYNCHRONIZATION?.toLowerCase() === 'true',
synchronizationPeriod: Number(CCDB_SYNCHRONIZATION_PERIOD) || 24 * 60 * 60 * 1000, // 1h in milliseconds
synchronizationPeriod: Number(CCDB_SYNCHRONIZATION_PERIOD) || 24 * 60 * 60 * 1000, // 1d in milliseconds
runInfoUrl: CCDB_RUN_INFO_URL,
},
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { getGoodPhysicsRunsWithMissingTfTimestamps } = require('../../services/run/getRunsMissingTfTimestamps.js');
const { runService } = require('../../services/run/RunService.js');
const { LogManager } = require('@aliceo2/web-ui');

/**
* Synchronizer for CCDB data
Expand All @@ -10,6 +11,7 @@ class CcdbSynchronizer {
* @param {string} runInfoUrl the CCDB URL where run information is to be retrieved
*/
constructor(runInfoUrl) {
this._logger = LogManager.getLogger(CcdbSynchronizer.name);
this._runInfoUrl = runInfoUrl;
}

Expand All @@ -20,14 +22,21 @@ class CcdbSynchronizer {
* @return {Promise<void>} resolves once all runs have been updated
*/
async syncFirstAndLastTf(synchronizeAfter) {
const runs = await getGoodPhysicsRunsWithMissingTfTimestamps(synchronizeAfter);
try {
this._logger.debugMessage('Starting to sync runs TF with CCDB');
const runNumbers = (await getGoodPhysicsRunsWithMissingTfTimestamps(synchronizeAfter)).map(({ runNumber }) => runNumber);
this._logger.debugMessage(`Runs to sync: ${runNumbers.join(', ')}`);

for (const { runNumber } of runs) {
const timeframes = await this._getRunStartAndEndTimeframes(runNumber);
for (const runNumber of runNumbers) {
const timeframes = await this._getRunStartAndEndTimeframes(runNumber);

if (timeframes.firstTfTimestamp || timeframes.lastTfTimestamp) {
await runService.update({ runNumber }, { runPatch: timeframes });
if (timeframes.firstTfTimestamp || timeframes.lastTfTimestamp) {
await runService.update({ runNumber }, { runPatch: timeframes });
}
}
this._logger.debugMessage('Synchronization of TF done');
} catch (e) {
this._logger.errorMessage(`Synchronization failed:\n ${e.stack}`);

Check warning on line 39 in lib/server/externalServicesSynchronization/ccdb/CcdbSynchronizer.js

View check run for this annotation

Codecov / codecov/patch

lib/server/externalServicesSynchronization/ccdb/CcdbSynchronizer.js#L39

Added line #L39 was not covered by tests
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class MonAlisaClient {

/**
* Get data passes from MonAlisa associated with at least one data pass
* @return {{properties: SimulationPass, associations: SimulationPassAssociations}[]} simulation passes list
* @return {Promise<{properties: SimulationPass, associations: SimulationPassAssociations}[]>} simulation passes list
*/
async getSimulationPasses() {
const payload = await this._fetchSimulationPasses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class MonAlisaSynchronizer {
*/
async _synchronizeDataPassesFromMonAlisa() {
try {
this._logger.debugMessage('Starting synchronization of Data Passes');
const descriptionToLastSeenAndIdAndStatus = await this._getAllDataPassVersionsLastSeenAndIdAndLastStatus();
const allMonAlisaDataPassesVersions = await this._monAlisaInterface.getDataPassesVersions();
const monAlisaDataPassesVersionsToBeUpdated = allMonAlisaDataPassesVersions
Expand Down Expand Up @@ -271,6 +272,7 @@ class MonAlisaSynchronizer {
*/
async _synchronizeSimulationPassesFromMonAlisa() {
try {
this._logger.debugMessage('Starting synchronization of Simulation Passes');
const simulationPasses = await this._monAlisaInterface.getSimulationPasses();
for (const simulationPass of simulationPasses) {
try {
Expand Down

0 comments on commit 6eaf6bf

Please sign in to comment.