Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add has_completed_background_update
Browse files Browse the repository at this point in the history
This allows checking if a specific background update has completed.
  • Loading branch information
erikjohnston committed Sep 24, 2019
1 parent 367158a commit 2135c19
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion synapse/storage/background_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,37 @@ def has_completed_background_updates(self):
"background_updates",
keyvalues=None,
retcol="1",
desc="check_background_updates",
desc="has_completed_background_updates",
)
if not updates:
self._all_done = True
return True

return False

async def has_completed_background_update(self, update_name):
"""Check if the given background update has finished running.
Returns:
Deferred[bool]

This comment has been minimized.

Copy link
@richvdh

richvdh Sep 25, 2019

Member

no it doesn't.

convention for async functions is just to document the type that you'll get once the coroutine completes, ie bool. Better yet, use a type hint on the function (-> bool)

"""

if self._all_done:
return True

if update_name in self._background_update_queue:
return False

update_exists = await self._simple_select_one_onecol(
"background_updates",
keyvalues={"update_name": update_name},
retcol="1",
desc="has_completed_background_update",
allow_none=True,
)

return not update_exists

@defer.inlineCallbacks
def do_next_background_update(self, desired_duration_ms):
"""Does some amount of work on the next queued background update
Expand Down

0 comments on commit 2135c19

Please sign in to comment.