mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Make do_next_background_update return a bool
returning a None or an int that we don't use is confusing.
This commit is contained in:
parent
51f4d52cb4
commit
b4c2234232
@ -111,7 +111,7 @@ class BackgroundUpdater(object):
|
|||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Error doing update")
|
logger.exception("Error doing update")
|
||||||
else:
|
else:
|
||||||
if result is None:
|
if result:
|
||||||
logger.info(
|
logger.info(
|
||||||
"No more background updates to do."
|
"No more background updates to do."
|
||||||
" Unscheduling background update task."
|
" Unscheduling background update task."
|
||||||
@ -169,9 +169,7 @@ class BackgroundUpdater(object):
|
|||||||
|
|
||||||
return not update_exists
|
return not update_exists
|
||||||
|
|
||||||
async def do_next_background_update(
|
async def do_next_background_update(self, desired_duration_ms: float) -> bool:
|
||||||
self, desired_duration_ms: float
|
|
||||||
) -> Optional[int]:
|
|
||||||
"""Does some amount of work on the next queued background update
|
"""Does some amount of work on the next queued background update
|
||||||
|
|
||||||
Returns once some amount of work is done.
|
Returns once some amount of work is done.
|
||||||
@ -180,7 +178,7 @@ class BackgroundUpdater(object):
|
|||||||
desired_duration_ms(float): How long we want to spend
|
desired_duration_ms(float): How long we want to spend
|
||||||
updating.
|
updating.
|
||||||
Returns:
|
Returns:
|
||||||
None if there is no more work to do, otherwise an int
|
True if there is no more work to do, otherwise False
|
||||||
"""
|
"""
|
||||||
if not self._background_update_queue:
|
if not self._background_update_queue:
|
||||||
updates = await self.db.simple_select_list(
|
updates = await self.db.simple_select_list(
|
||||||
@ -195,14 +193,14 @@ class BackgroundUpdater(object):
|
|||||||
|
|
||||||
if not self._background_update_queue:
|
if not self._background_update_queue:
|
||||||
# no work left to do
|
# no work left to do
|
||||||
return None
|
return True
|
||||||
|
|
||||||
# pop from the front, and add back to the back
|
# pop from the front, and add back to the back
|
||||||
update_name = self._background_update_queue.pop(0)
|
update_name = self._background_update_queue.pop(0)
|
||||||
self._background_update_queue.append(update_name)
|
self._background_update_queue.append(update_name)
|
||||||
|
|
||||||
res = await self._do_background_update(update_name, desired_duration_ms)
|
res = await self._do_background_update(update_name, desired_duration_ms)
|
||||||
return res
|
return False
|
||||||
|
|
||||||
async def _do_background_update(
|
async def _do_background_update(
|
||||||
self, update_name: str, desired_duration_ms: float
|
self, update_name: str, desired_duration_ms: float
|
||||||
|
@ -56,7 +56,7 @@ class BackgroundUpdateTestCase(unittest.HomeserverTestCase):
|
|||||||
),
|
),
|
||||||
by=0.1,
|
by=0.1,
|
||||||
)
|
)
|
||||||
self.assertIsNotNone(res)
|
self.assertFalse(res)
|
||||||
|
|
||||||
# on the first call, we should get run with the default background update size
|
# on the first call, we should get run with the default background update size
|
||||||
self.update_handler.assert_called_once_with(
|
self.update_handler.assert_called_once_with(
|
||||||
@ -79,7 +79,7 @@ class BackgroundUpdateTestCase(unittest.HomeserverTestCase):
|
|||||||
result = self.get_success(
|
result = self.get_success(
|
||||||
self.updates.do_next_background_update(target_background_update_duration_ms)
|
self.updates.do_next_background_update(target_background_update_duration_ms)
|
||||||
)
|
)
|
||||||
self.assertIsNotNone(result)
|
self.assertFalse(result)
|
||||||
self.update_handler.assert_called_once()
|
self.update_handler.assert_called_once()
|
||||||
|
|
||||||
# third step: we don't expect to be called any more
|
# third step: we don't expect to be called any more
|
||||||
@ -87,5 +87,5 @@ class BackgroundUpdateTestCase(unittest.HomeserverTestCase):
|
|||||||
result = self.get_success(
|
result = self.get_success(
|
||||||
self.updates.do_next_background_update(target_background_update_duration_ms)
|
self.updates.do_next_background_update(target_background_update_duration_ms)
|
||||||
)
|
)
|
||||||
self.assertIsNone(result)
|
self.assertTrue(result)
|
||||||
self.assertFalse(self.update_handler.called)
|
self.assertFalse(self.update_handler.called)
|
||||||
|
Loading…
Reference in New Issue
Block a user