Add requestDataFromPeers
This commit is contained in:
parent
091a8d4bd2
commit
9dda743ba0
@ -195,6 +195,7 @@ export class Database {
|
|||||||
service.setNotifications(data.data);
|
service.setNotifications(data.data);
|
||||||
} else if (data.type === 'TO_DOWNLOAD') {
|
} else if (data.type === 'TO_DOWNLOAD') {
|
||||||
// Download the missing data
|
// Download the missing data
|
||||||
|
let requestedStateId = [];
|
||||||
for (const hash of data.data) {
|
for (const hash of data.data) {
|
||||||
try {
|
try {
|
||||||
const value = await service.fetchValueFromStorage(hash);
|
const value = await service.fetchValueFromStorage(hash);
|
||||||
@ -205,6 +206,14 @@ export class Database {
|
|||||||
} else {
|
} else {
|
||||||
// We first request the data from managers
|
// We first request the data from managers
|
||||||
console.log('Request data from managers of the process');
|
console.log('Request data from managers of the process');
|
||||||
|
// get the diff from db
|
||||||
|
const diff = await service.getDiffByValue(hash);
|
||||||
|
const processId = diff.process_id;
|
||||||
|
const stateId = diff.state_id;
|
||||||
|
if (!requestedStateId.includes(stateId)) {
|
||||||
|
await service.requestDataFromPeers(processId, stateId);
|
||||||
|
requestedStateId.push(stateId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -1299,4 +1299,13 @@ export default class Services {
|
|||||||
console.error("Failed to get processes:", e);
|
console.error("Failed to get processes:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async requestDataFromPeers(processId: string, stateId: string) {
|
||||||
|
try {
|
||||||
|
const res = this.sdkClient.request_data(processId, [stateId]);
|
||||||
|
await this.handleApiReturn(res);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user