(sourceModel, targetModel, since, options, callback)
| 1203 | }; |
| 1204 | |
| 1205 | function tryReplicate(sourceModel, targetModel, since, options, callback) { |
| 1206 | const Change = sourceModel.getChangeModel(); |
| 1207 | const TargetChange = targetModel.getChangeModel(); |
| 1208 | const changeTrackingEnabled = Change && TargetChange; |
| 1209 | let replicationChunkSize = REPLICATION_CHUNK_SIZE; |
| 1210 | |
| 1211 | if (sourceModel.settings && sourceModel.settings.replicationChunkSize) { |
| 1212 | replicationChunkSize = sourceModel.settings.replicationChunkSize; |
| 1213 | } |
| 1214 | |
| 1215 | assert( |
| 1216 | changeTrackingEnabled, |
| 1217 | 'You must enable change tracking before replicating', |
| 1218 | ); |
| 1219 | |
| 1220 | let diff, updates, newSourceCp, newTargetCp; |
| 1221 | |
| 1222 | const tasks = [ |
| 1223 | checkpoints, |
| 1224 | getSourceChanges, |
| 1225 | getDiffFromTarget, |
| 1226 | createSourceUpdates, |
| 1227 | bulkUpdate, |
| 1228 | ]; |
| 1229 | |
| 1230 | async.waterfall(tasks, done); |
| 1231 | |
| 1232 | function getSourceChanges(cb) { |
| 1233 | utils.downloadInChunks( |
| 1234 | options.filter, |
| 1235 | replicationChunkSize, |
| 1236 | function(filter, pagingCallback) { |
| 1237 | sourceModel.changes(since.source, filter, pagingCallback); |
| 1238 | }, |
| 1239 | debug.enabled ? log : cb, |
| 1240 | ); |
| 1241 | |
| 1242 | function log(err, result) { |
| 1243 | if (err) return cb(err); |
| 1244 | debug('\tusing source changes'); |
| 1245 | result.forEach(function(it) { debug('\t\t%j', it); }); |
| 1246 | cb(err, result); |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | function getDiffFromTarget(sourceChanges, cb) { |
| 1251 | utils.uploadInChunks( |
| 1252 | sourceChanges, |
| 1253 | replicationChunkSize, |
| 1254 | function(smallArray, chunkCallback) { |
| 1255 | return targetModel.diff(since.target, smallArray, chunkCallback); |
| 1256 | }, |
| 1257 | debug.enabled ? log : cb, |
| 1258 | ); |
| 1259 | |
| 1260 | function log(err, result) { |
| 1261 | if (err) return cb(err); |
| 1262 | if (result.conflicts && result.conflicts.length) { |
no outgoing calls
no test coverage detected
searching dependent graphs…