diff --git a/lib/application.js b/lib/application.js index ae0cf6bb53..733fab3514 100644 --- a/lib/application.js +++ b/lib/application.js @@ -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)), { - wait: 3 * 1000, + wait: 10 * 1000, every: ccdbConfig.synchronizationPeriod, }, ); diff --git a/lib/config/services.js b/lib/config/services.js index 87c6dfb9b4..052f4a79b8 100644 --- a/lib/config/services.js +++ b/lib/config/services.js @@ -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, }, }; diff --git a/lib/server/externalServicesSynchronization/ccdb/CcdbSynchronizer.js b/lib/server/externalServicesSynchronization/ccdb/CcdbSynchronizer.js index 7a9ee7e160..3acb210468 100644 --- a/lib/server/externalServicesSynchronization/ccdb/CcdbSynchronizer.js +++ b/lib/server/externalServicesSynchronization/ccdb/CcdbSynchronizer.js @@ -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 @@ -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; } @@ -20,14 +22,21 @@ class CcdbSynchronizer { * @return {Promise} 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}`); } } diff --git a/lib/server/externalServicesSynchronization/monalisa/MonAlisaClient.js b/lib/server/externalServicesSynchronization/monalisa/MonAlisaClient.js index 77e8e93d90..4c528a0bb3 100644 --- a/lib/server/externalServicesSynchronization/monalisa/MonAlisaClient.js +++ b/lib/server/externalServicesSynchronization/monalisa/MonAlisaClient.js @@ -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(); diff --git a/lib/server/externalServicesSynchronization/monalisa/MonAlisaSynchronizer.js b/lib/server/externalServicesSynchronization/monalisa/MonAlisaSynchronizer.js index 4494451720..6acafd32cf 100644 --- a/lib/server/externalServicesSynchronization/monalisa/MonAlisaSynchronizer.js +++ b/lib/server/externalServicesSynchronization/monalisa/MonAlisaSynchronizer.js @@ -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 @@ -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 {