#98, better error reporting for sync setup

This commit is contained in:
azivner 2018-07-25 22:54:37 +02:00
parent d39cdbfada
commit 02dc7b199b
7 changed files with 33 additions and 22 deletions

View file

@ -223,9 +223,14 @@ addTabHandler((function() {
});
$syncToServerButton.click(async () => {
await server.post("setup/sync-to-server");
const resp = await server.post("setup/sync-to-server");
infoService.showMessage("Sync has been established to the server instance. It will take some time to finish.");
if (resp.success) {
infoService.showMessage("Sync has been established to the server instance. It will take some time to finish.");
}
else {
infoService.showError('Sync setup failed: ' + resp.error);
}
});
return {

View file

@ -105,9 +105,11 @@ function SetupModel() {
this.step('sync-in-progress');
setInterval(checkOutstandingSyncs, 1000);
hideAlert();
}
else {
showAlert('Sync setup failed: ', resp.error);
showAlert('Sync setup failed: ' + resp.error);
}
}
};
@ -130,6 +132,10 @@ function showAlert(message) {
$("#alert").show();
}
function hideAlert() {
$("#alert").hide();
}
ko.applyBindings(new SetupModel(), document.getElementById('setup-dialog'));
$("#setup-dialog").show();

View file

@ -38,7 +38,12 @@ async function setupSyncToSyncServer() {
rpOpts.proxy = syncProxy;
}
await rp(rpOpts);
try {
await rp(rpOpts);
}
catch (e) {
return { success: false, error: e.message };
}
// this is completely new sync, need to reset counters. If this would not be new sync,
// the previous request would have failed.
@ -46,6 +51,8 @@ async function setupSyncToSyncServer() {
await optionService.setOption('lastSyncedPull', 0);
syncService.sync();
return { success: true };
}
async function saveSyncSeed(req) {

View file

@ -19,6 +19,5 @@ async function addNoteEvent(noteId, comment) {
}
module.exports = {
addEvent,
addNoteEvent
addEvent
};

View file

@ -96,6 +96,8 @@ async function pullSync(syncContext) {
const lastSyncedPull = await getLastSyncedPull();
const changesUri = '/api/sync/changed?lastSyncId=' + lastSyncedPull;
const startDate = new Date();
const resp = await syncRequest(syncContext, 'GET', changesUri);
stats.outstandingPulls = resp.maxSyncId - lastSyncedPull;
@ -105,21 +107,19 @@ async function pullSync(syncContext) {
break;
}
log.info("Pulled " + rows.length + " changes from " + changesUri);
log.info("Pulled " + rows.length + " changes from " + changesUri + " in "
+ (new Date().getTime() - startDate.getTime()) + "ms");
for (const {sync, entity} of rows) {
if (sourceIdService.isLocalSourceId(sync.sourceId)) {
// too noisy
//log.info(`Skipping pull #${sync.id} ${sync.entityName} ${sync.entityId} because ${sync.sourceId} is a local source id.`);
}
else {
if (!sourceIdService.isLocalSourceId(sync.sourceId)) {
await syncUpdateService.updateEntity(sync, entity, syncContext.sourceId);
}
stats.outstandingPulls = resp.maxSyncId - sync.id;
await setLastSyncedPull(sync.id);
}
await setLastSyncedPull(rows[rows.length - 1].sync.id);
}
log.info("Finished pull");
@ -163,14 +163,15 @@ async function pushSync(syncContext) {
}
const syncRecords = await getSyncRecords(filteredSyncs);
log.info(`Pushing ${syncRecords.length} syncs.`);
const startDate = new Date();
await syncRequest(syncContext, 'PUT', '/api/sync/update', {
sourceId: sourceIdService.getCurrentSourceId(),
entities: syncRecords
});
log.info(`Pushing ${syncRecords.length} syncs in ` + (new Date().getTime() - startDate.getTime()) + "ms");
lastSyncedPush = syncRecords[syncRecords.length - 1].sync.id;
await setLastSyncedPush(lastSyncedPush);

View file

@ -54,12 +54,6 @@ async function addEntitySync(entityName, entityId, sourceId) {
sourceId: sourceId || cls.getSourceId() || sourceIdService.getCurrentSourceId()
});
if (!await syncOptions.isSyncSetup()) {
// this is because the "server" instances shouldn't have outstanding pushes
// useful when you fork the DB for new "client" instance, it won't try to sync the whole DB
await sql.execute("UPDATE options SET value = (SELECT MAX(id) FROM sync) WHERE name IN('lastSyncedPush', 'lastSyncedPull')");
}
eventService.emit(eventService.ENTITY_CHANGED, {
entityName,
entityId

View file

@ -57,7 +57,6 @@ async function updateNote(entity, sourceId) {
await sql.replace("notes", entity);
await syncTableService.addNoteSync(entity.noteId, sourceId);
await eventLogService.addNoteEvent(entity.noteId, "Synced note <note>");
});
log.info("Update/sync note " + entity.noteId);