* Writes configuration version to the management database * * @param {object} cachedOverlay Latest stored configuration version * for freshness comparison purposes * @param {object} remoteOverlay New configuration version * @param {werelogs~Logger} log Request-scoped logger * @param {func
(cachedOverlay, remoteOverlay, log, cb)
| 147 | * @returns {undefined} |
| 148 | */ |
| 149 | function saveConfigurationVersion(cachedOverlay, remoteOverlay, log, cb) { |
| 150 | if (remoteOverlayIsNewer(cachedOverlay, remoteOverlay)) { |
| 151 | const objName = `configuration/overlay/${remoteOverlay.version}`; |
| 152 | metadata.putObjectMD(managementDatabaseName, objName, remoteOverlay, |
| 153 | {}, log, error => { |
| 154 | if (error) { |
| 155 | const exceptionError = reshapeExceptionError(error); |
| 156 | log.error('could not save configuration', |
| 157 | { error: exceptionError, |
| 158 | method: 'saveConfigurationVersion', |
| 159 | configurationVersion: remoteOverlay.version }); |
| 160 | cb(exceptionError); |
| 161 | return; |
| 162 | } |
| 163 | metadata.putObjectMD(managementDatabaseName, |
| 164 | latestOverlayVersionKey, remoteOverlay.version, {}, log, |
| 165 | error => { |
| 166 | if (error) { |
| 167 | log.error('could not save configuration version', { |
| 168 | configurationVersion: remoteOverlay.version, |
| 169 | }); |
| 170 | } |
| 171 | cb(error, remoteOverlay); |
| 172 | }); |
| 173 | }); |
| 174 | } else { |
| 175 | log.debug('no remote configuration to cache yet'); |
| 176 | process.nextTick(cb, null, remoteOverlay); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Loads the latest cached configuration overlay from the management |
no test coverage detected