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

Store backend syncers in a thread-safe dict

parent 2ed93a9c
...@@ -32,6 +32,7 @@ from agkyra.config import AgkyraConfig, AGKYRA_DIR ...@@ -32,6 +32,7 @@ from agkyra.config import AgkyraConfig, AGKYRA_DIR
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
SYNCERS = utils.ThreadSafeDict()
class SessionHelper(object): class SessionHelper(object):
...@@ -193,10 +194,16 @@ class WebSocketProtocol(WebSocket): ...@@ -193,10 +194,16 @@ class WebSocketProtocol(WebSocket):
exclude=None) exclude=None)
status = dict( status = dict(
progress=0, synced=0, unsynced=0, paused=True, can_sync=False) progress=0, synced=0, unsynced=0, paused=True, can_sync=False)
file_syncer = None
cnf = AgkyraConfig() cnf = AgkyraConfig()
essentials = ('url', 'token', 'container', 'directory') essentials = ('url', 'token', 'container', 'directory')
@property
def syncer(self):
with SYNCERS.lock() as d:
for sync_key, sync_obj in d.items():
return sync_obj
return None
def heartbeat(self): def heartbeat(self):
db = sqlite3.connect(self.session_db) db = sqlite3.connect(self.session_db)
while True: while True:
...@@ -354,12 +361,15 @@ class WebSocketProtocol(WebSocket): ...@@ -354,12 +361,15 @@ class WebSocketProtocol(WebSocket):
**kwargs) **kwargs)
master = pithos_client.PithosFileClient(syncer_settings) master = pithos_client.PithosFileClient(syncer_settings)
slave = localfs_client.LocalfsFileClient(syncer_settings) slave = localfs_client.LocalfsFileClient(syncer_settings)
self.syncer = syncer.FileSyncer(syncer_settings, master, slave) syncer_ = syncer.FileSyncer(syncer_settings, master, slave)
self.syncer_settings = syncer_settings self.syncer_settings = syncer_settings
self.syncer.initiate_probe() syncer_.initiate_probe()
except setup.ClientError: except setup.ClientError:
self.syncer = None syncer_ = None
raise raise
finally:
with SYNCERS.lock() as d:
d[0] = syncer_
# Syncer-related methods # Syncer-related methods
def get_status(self): def get_status(self):
...@@ -515,8 +525,6 @@ class WebSocketProtocol(WebSocket): ...@@ -515,8 +525,6 @@ class WebSocketProtocol(WebSocket):
self.send_json({'%s' % ce: ce.status, 'action': action}) self.send_json({'%s' % ce: ce.status, 'action': action})
return return
except Exception as e: except Exception as e:
from traceback import print_stack
print_stack(e)
self.send_json({'INTERNAL ERROR': 500}) self.send_json({'INTERNAL ERROR': 500})
LOG.error('EXCEPTION: %s' % e) LOG.error('EXCEPTION: %s' % e)
self.terminate() self.terminate()
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