Clean queue after sending
This commit is contained in:
parent
1c3116d9dc
commit
dfd6260a7a
3 changed files with 49 additions and 16 deletions
|
|
@ -88,19 +88,36 @@ export class Sync {
|
|||
}//}}}
|
||||
|
||||
static async nodesToServer() {//{{{
|
||||
try {
|
||||
const nodesToSend = await nodeStore.sendQueue.retrieve(100)
|
||||
const clientUUID = await nodeStore.getAppState('client_uuid')
|
||||
const request = {
|
||||
NodeData: JSON.stringify(nodesToSend),
|
||||
ClientUUID: clientUUID.value,
|
||||
}
|
||||
res = await API.query('POST', `/sync/to_server/${oldMax}/${offset}`, request)
|
||||
console.log(res)
|
||||
while(true) {
|
||||
try {
|
||||
// Send nodes in batches until everything is sent, or an error has occured.
|
||||
const nodesToSend = await nodeStore.sendQueue.retrieve(2)
|
||||
if (nodesToSend.length === 0)
|
||||
break
|
||||
console.debug(`Sending ${nodesToSend.length} node(s) to server`)
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
alert(e)
|
||||
const clientUUID = await nodeStore.getAppState('client_uuid')
|
||||
const request = {
|
||||
NodeData: JSON.stringify(nodesToSend),
|
||||
ClientUUID: clientUUID.value,
|
||||
}
|
||||
const res = await API.query('POST', '/sync/to_server', request)
|
||||
if (!res.OK) {
|
||||
// TODO - implement better error management here.
|
||||
console.log(res)
|
||||
alert(res)
|
||||
return
|
||||
}
|
||||
|
||||
// Nodes are archived on server and can now be deleted from the send queue.
|
||||
const keys = nodesToSend.map(node => node.ClientSequence)
|
||||
console.log(await nodeStore.sendQueue.delete(keys))
|
||||
|
||||
} catch (e) {
|
||||
console.trace(e)
|
||||
alert(e)
|
||||
return
|
||||
}
|
||||
}
|
||||
}//}}}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue