Add updateProcessesFromRelay
This commit is contained in:
parent
932b659c2b
commit
886778805d
@ -890,6 +890,24 @@ export default class Services {
|
|||||||
await this.restoreProcessesFromDB();
|
await this.restoreProcessesFromDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async updateProcessesFromRelay(processes: Record<string, Process>) {
|
||||||
|
const db = await Database.getInstance();
|
||||||
|
for (const [processId, process] of Object.entries(processes)) {
|
||||||
|
const processFromDb = await this.getProcess(processId);
|
||||||
|
if (!processFromDb) {
|
||||||
|
console.log(`Unknown process ${processId}, adding to db`);
|
||||||
|
await db.addObject({ storeName: 'processes', object: process, key: processId});
|
||||||
|
} else {
|
||||||
|
const missingStates = process.states.length - processFromDb.states.length;
|
||||||
|
if (missingStates < 0) {
|
||||||
|
// We are missing one or more states for a known process
|
||||||
|
// TODO send a request to process managers to get the missing states
|
||||||
|
console.log(`Missing ${missingStates} for process ${processId}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Restore process in wasm with persistent storage
|
// Restore process in wasm with persistent storage
|
||||||
public async restoreProcessesFromDB() {
|
public async restoreProcessesFromDB() {
|
||||||
const db = await Database.getInstance();
|
const db = await Database.getInstance();
|
||||||
@ -1082,7 +1100,6 @@ export default class Services {
|
|||||||
try {
|
try {
|
||||||
const handshakeMsg: HandshakeMessage = JSON.parse(parsedMsg);
|
const handshakeMsg: HandshakeMessage = JSON.parse(parsedMsg);
|
||||||
this.updateRelay(url, handshakeMsg.sp_address);
|
this.updateRelay(url, handshakeMsg.sp_address);
|
||||||
const processes = handshakeMsg.processes_list;
|
|
||||||
const members = handshakeMsg.peers_list;
|
const members = handshakeMsg.peers_list;
|
||||||
if (this.membersList && Object.keys(this.membersList).length === 0) {
|
if (this.membersList && Object.keys(this.membersList).length === 0) {
|
||||||
this.membersList = handshakeMsg.peers_list;
|
this.membersList = handshakeMsg.peers_list;
|
||||||
@ -1092,9 +1109,11 @@ export default class Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write processes to db
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
await this.restoreProcessesFromBackUp(processes);
|
const newProcesses = handshakeMsg.processes_list;
|
||||||
|
if (newProcesses && Object.keys(newProcesses).length !== 0) {
|
||||||
|
await this.updateProcessesFromRelay(newProcesses);
|
||||||
|
}
|
||||||
}, 500)
|
}, 500)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to parse init message:', e);
|
console.error('Failed to parse init message:', e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user