Make datastore find & update operations async
This commit is contained in:
parent
28e8b9025e
commit
e659d15384
@ -207,15 +207,20 @@ class Activity(Window, gtk.Container):
|
||||
self.jobject['preview'] = ''
|
||||
self.jobject['icon-color'] = profile.get_color().to_string()
|
||||
self.jobject.file_path = ''
|
||||
try:
|
||||
datastore.write(self.jobject)
|
||||
except Exception, e:
|
||||
logging.error(e)
|
||||
datastore.write(self.jobject,
|
||||
reply_handler=self._internal_jobject_create_cb,
|
||||
error_handler=self._internal_jobject_error_cb)
|
||||
else:
|
||||
self.jobject = None
|
||||
|
||||
self.connect('focus-out-event', self._focus_out_event_cb)
|
||||
|
||||
def _internal_jobject_create_cb(self):
|
||||
pass
|
||||
|
||||
def _internal_jobject_error_cb(self, err):
|
||||
logging.debug("Error creating activity datastore object: %s" % err)
|
||||
|
||||
def _focus_out_event_cb(self, widget, event):
|
||||
if self.jobject:
|
||||
self.save()
|
||||
@ -234,6 +239,12 @@ class Activity(Window, gtk.Container):
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def _internal_save_cb(self):
|
||||
pass
|
||||
|
||||
def _internal_save_error_cb(self, err):
|
||||
logging.debug("Error saving activity object to datastore: %s" % err)
|
||||
|
||||
def save(self):
|
||||
"""Request that the activity is saved to the Journal."""
|
||||
try:
|
||||
@ -241,7 +252,9 @@ class Activity(Window, gtk.Container):
|
||||
self.write_file()
|
||||
except NotImplementedError:
|
||||
self.jobject.file_path = ''
|
||||
datastore.write(self.jobject)
|
||||
datastore.write(self.jobject,
|
||||
reply_handler=self._internal_save_cb,
|
||||
error_handler=self._internal_save_error_cb)
|
||||
|
||||
def _internal_joined_cb(self, activity, success, err):
|
||||
"""Callback when join has finished"""
|
||||
|
@ -71,20 +71,22 @@ def get(object_id):
|
||||
def create():
|
||||
return DSObject(object_id=None, metadata={}, file_path=None)
|
||||
|
||||
def write(ds_object):
|
||||
def write(ds_object, reply_handler=None, error_handler=None):
|
||||
logging.debug('datastore.write')
|
||||
if ds_object.object_id:
|
||||
dbus_helpers.update(ds_object.object_id,
|
||||
ds_object.metadata,
|
||||
ds_object.file_path)
|
||||
ds_object.file_path,
|
||||
reply_handler=reply_handler,
|
||||
error_handler=error_handler)
|
||||
else:
|
||||
ds_object.object_id = dbus_helpers.create(ds_object.metadata,
|
||||
ds_object.file_path)
|
||||
# TODO: register the object for updates
|
||||
logging.debug('Written object %s to the datastore.' % ds_object.object_id)
|
||||
|
||||
def find(query):
|
||||
object_ids = dbus_helpers.find({})
|
||||
def find(query, reply_handler=None, error_handler=None):
|
||||
object_ids = dbus_helpers.find(query, reply_handler, error_handler)
|
||||
objects = []
|
||||
for object_id in object_ids:
|
||||
objects.append(get(object_id))
|
||||
|
@ -54,13 +54,18 @@ def create(properties, filename):
|
||||
logging.debug('dbus_helpers.create: ' + object_id)
|
||||
return object_id
|
||||
|
||||
def update(uid, properties, filename):
|
||||
def update(uid, properties, filename, reply_handler=None, error_handler=None):
|
||||
logging.debug('dbus_helpers.update: %s, %s, %s' % (uid, properties, filename))
|
||||
try:
|
||||
logging.debug(get_contents(filename))
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
_data_store.update(uid, dbus.Dictionary(properties), filename)
|
||||
if reply_handler and error_handler:
|
||||
_data_store.update(uid, dbus.Dictionary(properties), filename,
|
||||
reply_handler=reply_handler,
|
||||
error_handler=error_handler)
|
||||
else:
|
||||
_data_store.update(uid, dbus.Dictionary(properties), filename)
|
||||
|
||||
def get_properties(uid):
|
||||
props = _data_store.get_properties(uid)
|
||||
@ -76,8 +81,12 @@ def get_filename(uid):
|
||||
pass
|
||||
return filename
|
||||
|
||||
def find(query):
|
||||
return _data_store.find(query)
|
||||
def find(query, reply_handler, error_handler):
|
||||
if reply_handler and error_handler:
|
||||
return _data_store.find(query, reply_handler=reply_handler,
|
||||
error_handler=error_handler)
|
||||
else:
|
||||
return _data_store.find(query)
|
||||
"""
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user