|
@@ -8,9 +8,9 @@ const { format } = require('date-fns');
|
|
|
const dbs = ['coloring_ol']; // 需要同步的数据库, 主数据库(即syncevent表所在的库)放在第一个
|
|
const dbs = ['coloring_ol']; // 需要同步的数据库, 主数据库(即syncevent表所在的库)放在第一个
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * start sync from remote
|
|
|
|
|
|
|
+ * sync from remote
|
|
|
*/
|
|
*/
|
|
|
-async function start() {
|
|
|
|
|
|
|
+async function run() {
|
|
|
let delay = 30 * 1000; // sync freq
|
|
let delay = 30 * 1000; // sync freq
|
|
|
let localDBHash = {};
|
|
let localDBHash = {};
|
|
|
let remoteDBHash = {};
|
|
let remoteDBHash = {};
|
|
@@ -31,7 +31,7 @@ async function start() {
|
|
|
else seqDoc = new SyncSeq({});
|
|
else seqDoc = new SyncSeq({});
|
|
|
|
|
|
|
|
let count, localtb, remotetb, localdoc, remotedoc;
|
|
let count, localtb, remotetb, localdoc, remotedoc;
|
|
|
- setTimeout(async function run() {
|
|
|
|
|
|
|
+ setTimeout(async function cycleRun() {
|
|
|
try {
|
|
try {
|
|
|
let eventDocs = await synceventTB.find({ _id: { $gt: seq } }).limit(200).toArray() || [];
|
|
let eventDocs = await synceventTB.find({ _id: { $gt: seq } }).limit(200).toArray() || [];
|
|
|
count = 0;
|
|
count = 0;
|
|
@@ -92,8 +92,8 @@ async function start() {
|
|
|
console.error(err);
|
|
console.error(err);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (count > 0) setTimeout(run, 0);
|
|
|
|
|
- else setTimeout(run, delay);
|
|
|
|
|
|
|
+ if (count > 0) setTimeout(cycleRun, 0);
|
|
|
|
|
+ // else setTimeout(run, delay);
|
|
|
|
|
|
|
|
}, 0);
|
|
}, 0);
|
|
|
|
|
|
|
@@ -101,10 +101,10 @@ async function start() {
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
module.exports = {
|
|
|
- start
|
|
|
|
|
|
|
+ run
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
if (require.main == module) {
|
|
if (require.main == module) {
|
|
|
- start().catch(console.error);
|
|
|
|
|
|
|
+ run().catch(console.error);
|
|
|
}
|
|
}
|