Ticket #1160: 0001-add-API-to-check-wait-for-index-rebuild-to-finish.patch

File 0001-add-API-to-check-wait-for-index-rebuild-to-finish.patch, 2.4 KB (added by sascha_silbe, 13 years ago)

add API to check and wait for index rebuild to finish

  • src/carquinyol/datastore.py

    From 2388e86dcdcd6ebb13193091a8c3e03843b03285 Mon Sep 17 00:00:00 2001
    From: Sascha Silbe <sascha@silbe.org>
    Date: Wed, 12 Aug 2009 00:17:50 +0200
    Subject: [PATCH] add API to check/wait for index rebuild to finish
    
    ---
     src/carquinyol/datastore.py |   37 +++++++++++++++++++++++++++++++++++++
     1 files changed, 37 insertions(+), 0 deletions(-)
    
    diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
    index 0307046..c9c790c 100644
    a b class DataStore(dbus.service.Object): 
    5050    """
    5151
    5252    def __init__(self, **options):
     53        self._wait_ready_queue = []
    5354        bus_name = dbus.service.BusName(DS_SERVICE,
    5455                                        bus=dbus.SessionBus(),
    5556                                        replace_existing=False,
    class DataStore(dbus.service.Object): 
    109110        if not uids:
    110111            logging.debug('Finished updating index.')
    111112            layoutmanager.get_instance().index_updated = True
     113            self.Ready()
     114            for callback in self._wait_ready_queue:
     115                callback()
     116
     117            self._wait_ready_queue = []
    112118            return False
    113119        else:
    114120            return True
    class DataStore(dbus.service.Object): 
    342348    @dbus.service.signal(DS_DBUS_INTERFACE, signature="a{sv}")
    343349    def Unmounted(self, descriptor):
    344350        pass
     351
     352    @dbus.service.method(DS_DBUS_INTERFACE,
     353                         in_signature='',
     354                         out_signature='b')
     355    def check_ready(self):
     356        """Check whether datastore is ready for processing (regular) API
     357        calls.
     358
     359        Return True if datastore is fully operational.
     360        """
     361        return layoutmanager.get_instance().index_updated
     362
     363    @dbus.service.method(DS_DBUS_INTERFACE,
     364             in_signature='',
     365             out_signature='',
     366             async_callbacks=('async_cb', 'async_err_cb'))
     367    def wait_ready(self, async_cb, async_err_cb):
     368        """Block until the datastore is ready for processing (regular) API
     369        calls.
     370        """
     371        if layoutmanager.get_instance().index_updated:
     372            async_cb()
     373            return
     374
     375        self._wait_ready_queue.append(async_cb)
     376
     377    @dbus.service.signal(DS_DBUS_INTERFACE, signature='')
     378    def Ready(self):
     379        """Signal emitted after datastore is ready for processing API calls.
     380        """
     381        pass