diff options
author | Erik Johnston <erik@matrix.org> | 2019-09-24 14:18:31 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2019-09-24 15:53:17 +0100 |
commit | 2135c198d17b41297511a2fc3b39551d160069b2 (patch) | |
tree | 9a3c7e47571dc5507f7f516d6eed8186a0ece45f /synapse/storage/background_updates.py | |
parent | Add wrap_as_background_process decorator. (diff) | |
download | synapse-2135c198d17b41297511a2fc3b39551d160069b2.tar.xz |
Add has_completed_background_update
This allows checking if a specific background update has completed.
Diffstat (limited to 'synapse/storage/background_updates.py')
-rw-r--r-- | synapse/storage/background_updates.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/synapse/storage/background_updates.py b/synapse/storage/background_updates.py index e5f0668f09..3fc25cd828 100644 --- a/synapse/storage/background_updates.py +++ b/synapse/storage/background_updates.py @@ -140,7 +140,7 @@ class BackgroundUpdateStore(SQLBaseStore): "background_updates", keyvalues=None, retcol="1", - desc="check_background_updates", + desc="has_completed_background_updates", ) if not updates: self._all_done = True @@ -148,6 +148,29 @@ class BackgroundUpdateStore(SQLBaseStore): return False + async def has_completed_background_update(self, update_name): + """Check if the given background update has finished running. + + Returns: + Deferred[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 |