Slave: wait before sync on master-change
When Update master event occurs, master needs time to sync its missing data, so slaves should sync only after BACKUP_INTERVAL
This commit is contained in:
parent
15d36eb088
commit
1fcd62f2e5
@ -154,7 +154,7 @@ function connectToMaster(i = 0, init = false) {
|
|||||||
connectWS(floID).then(ws => {
|
connectWS(floID).then(ws => {
|
||||||
ws.floID = floID;
|
ws.floID = floID;
|
||||||
ws.onclose = () => connectToMaster(i);
|
ws.onclose = () => connectToMaster(i);
|
||||||
serveAsSlave(ws);
|
serveAsSlave(ws, init);
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.log(`Node(${floID}) is offline`);
|
console.log(`Node(${floID}) is offline`);
|
||||||
connectToMaster(i + 1, init)
|
connectToMaster(i + 1, init)
|
||||||
@ -170,10 +170,10 @@ function serveAsMaster(init) {
|
|||||||
app.resume();
|
app.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
function serveAsSlave(ws) {
|
function serveAsSlave(ws, init) {
|
||||||
console.debug('Starting slave process');
|
console.debug('Starting slave process');
|
||||||
app.pause();
|
app.pause();
|
||||||
slave.start(ws);
|
slave.start(ws, init);
|
||||||
mod = SLAVE_MODE;
|
mod = SLAVE_MODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ var masterWS = null; //Container for Master websocket connection
|
|||||||
|
|
||||||
var intervalID = null;
|
var intervalID = null;
|
||||||
|
|
||||||
function startSlaveProcess(ws) {
|
function startSlaveProcess(ws, init) {
|
||||||
if (!ws) throw Error("Master WS connection required");
|
if (!ws) throw Error("Master WS connection required");
|
||||||
//stop existing process
|
//stop existing process
|
||||||
stopSlaveProcess();
|
stopSlaveProcess();
|
||||||
@ -30,7 +30,8 @@ function startSlaveProcess(ws) {
|
|||||||
message.sign = floCrypto.signData(message.type + "|" + message.req_time, global.myPrivKey);
|
message.sign = floCrypto.signData(message.type + "|" + message.req_time, global.myPrivKey);
|
||||||
ws.send(JSON.stringify(message));
|
ws.send(JSON.stringify(message));
|
||||||
//start sync
|
//start sync
|
||||||
requestInstance.open();
|
if (init)
|
||||||
|
requestInstance.open();
|
||||||
intervalID = setInterval(() => requestInstance.open(), BACKUP_INTERVAL);
|
intervalID = setInterval(() => requestInstance.open(), BACKUP_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user