Commit 5f9e8ba3 authored by Stavros Sachtouris's avatar Stavros Sachtouris Committed by Giorgos Korfiatis
Browse files

Mind failed syncs in progress report reporting

At the backend level, some syncing operations may fail and restart
again. Failed operations will produce a SyncErrorMessage, which is
consumed by the UI, increasing the corresponding "failed" counter.

This allows the GUI to correctly calculate the number of synced
and unsynced files.
parent b6c2a013
......@@ -17,7 +17,9 @@ var NOTIFICATION = {
function is_up(code) { return (code / 100 >> 0) === 1; }
function has_settings_error(code) { return (code / 200 >> 0) === 2; }
function remaining(status) { return status.unsynced - status.synced; }
function remaining(status) {
return status.unsynced - (status.synced + status.failed);
}
var ntf_title = {
'info': 'Agkyra Notification',
......
......@@ -39,7 +39,7 @@ var globals = {
directory: null,
exclude: null
},
status: {synced: 0, unsynced: 0, code: STATUS['UNINITIALIZED']},
status: {synced: 0, unsynced: 0, failed: 0, code: STATUS['UNINITIALIZED']},
authenticated: false,
open_settings: false,
settings_are_open: false,
......@@ -82,7 +82,7 @@ function put_settings(socket, new_settings) {
function get_status(socket) {
send_json(socket, {'method': 'get', 'path': 'status'});
} // expected response {"synced":.., "unsynced":.., "code":..}
} // expected response {"synced":.., "unsynced":.., "failed":..., code":..}
// Connect to helper
......
......@@ -252,14 +252,13 @@ class WebSocketProtocol(WebSocket):
-- GET STATUS --
GUI: {"method": "get", "path": "status"}
HELPER: {"code": <int>,
"synced": <int>,
"unsynced": <int>,
"synced": <int>, "unsynced": <int>, "failed": <int>,
"action": "get status"
} or {<ERROR>: <ERROR CODE>, "action": "get status"}
"""
status = utils.ThreadSafeDict()
with status.lock() as d:
d.update(code=STATUS['UNINITIALIZED'], synced=0, unsynced=0)
d.update(code=STATUS['UNINITIALIZED'], synced=0, unsynced=0, failed=0)
ui_id = None
session_db, session_relation = None, None
......@@ -279,7 +278,7 @@ class WebSocketProtocol(WebSocket):
if self.syncer.paused:
d['code'] = STATUS['PAUSED']
elif d['code'] != STATUS['PAUSING'] or (
d['unsynced'] == d['synced']):
d['unsynced'] == d['synced'] + d['failed']):
d['code'] = STATUS['SYNCING']
with self.status.lock() as d:
return d.get(key, None) if key else dict(d)
......@@ -441,10 +440,10 @@ class WebSocketProtocol(WebSocket):
"""Update status by consuming and understanding syncer messages"""
if self.can_sync():
msg = self.syncer.get_next_message()
if not msg:
with self.status.lock() as d:
if d['unsynced'] == d['synced']:
d.update(unsynced=0, synced=0)
# if not msg:
# with self.status.lock() as d:
# if d['unsynced'] == d['synced'] + d['failed']:
# d.update(unsynced=0, synced=0, failed=0)
while msg:
if isinstance(msg, messaging.SyncMessage):
LOG.error('UNSYNCED +1')
......@@ -452,6 +451,9 @@ class WebSocketProtocol(WebSocket):
elif isinstance(msg, messaging.AckSyncMessage):
LOG.error('SYNCED +1')
self.set_status(synced=self.get_status('synced') + 1)
elif isinstance(msg, messaging.SyncErrorMessage):
LOG.error('FAILED +1')
self.set_status(failed=self.get_status('failed') + 1)
elif isinstance(msg, messaging.LocalfsSyncDisabled):
self.set_status(code=STATUS['DIRECTORY ERROR'])
self.syncer.stop_all_daemons()
......@@ -461,10 +463,10 @@ class WebSocketProtocol(WebSocket):
LOG.debug('Backend message: %s' % msg.name)
# Limit the amount of messages consumed each time
max_consumption -= 1
if not max_consumption:
break
else:
if max_consumption:
msg = self.syncer.get_next_message()
else:
break
def can_sync(self):
"""Check if settings are enough to setup a syncing proccess"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment