Make has_completed_background_updates async

(Almost) everywhere that uses it is happy with an awaitable.
This commit is contained in:
Richard van der Hoff 2020-03-31 17:25:10 +01:00
parent cfe8c8ab8e
commit 26d17b9bdc
2 changed files with 6 additions and 5 deletions

View File

@ -119,12 +119,11 @@ class BackgroundUpdater(object):
self._all_done = True self._all_done = True
return None return None
@defer.inlineCallbacks async def has_completed_background_updates(self) -> bool:
def has_completed_background_updates(self):
"""Check if all the background updates have completed """Check if all the background updates have completed
Returns: Returns:
Deferred[bool]: True if all background updates have completed True if all background updates have completed
""" """
# if we've previously determined that there is nothing left to do, that # if we've previously determined that there is nothing left to do, that
# is easy # is easy
@ -138,7 +137,7 @@ class BackgroundUpdater(object):
# otherwise, check if there are updates to be run. This is important, # otherwise, check if there are updates to be run. This is important,
# as we may be running on a worker which doesn't perform the bg updates # as we may be running on a worker which doesn't perform the bg updates
# itself, but still wants to wait for them to happen. # itself, but still wants to wait for them to happen.
updates = yield self.db.simple_select_onecol( updates = await self.db.simple_select_onecol(
"background_updates", "background_updates",
keyvalues=None, keyvalues=None,
retcol="1", retcol="1",

View File

@ -11,7 +11,9 @@ class BackgroundUpdateTestCase(unittest.HomeserverTestCase):
def prepare(self, reactor, clock, homeserver): def prepare(self, reactor, clock, homeserver):
self.updates = self.hs.get_datastore().db.updates # type: BackgroundUpdater self.updates = self.hs.get_datastore().db.updates # type: BackgroundUpdater
# the base test class should have run the real bg updates for us # the base test class should have run the real bg updates for us
self.assertTrue(self.updates.has_completed_background_updates()) self.assertTrue(
self.get_success(self.updates.has_completed_background_updates())
)
self.update_handler = Mock() self.update_handler = Mock()
self.updates.register_background_update_handler( self.updates.register_background_update_handler(