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

Commit 2135c19

Browse files
committed
Add has_completed_background_update
This allows checking if a specific background update has completed.
1 parent 367158a commit 2135c19

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

synapse/storage/background_updates.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,37 @@ def has_completed_background_updates(self):
140140
"background_updates",
141141
keyvalues=None,
142142
retcol="1",
143-
desc="check_background_updates",
143+
desc="has_completed_background_updates",
144144
)
145145
if not updates:
146146
self._all_done = True
147147
return True
148148

149149
return False
150150

151+
async def has_completed_background_update(self, update_name):
152+
"""Check if the given background update has finished running.
153+
154+
Returns:
155+
Deferred[bool]
156+
"""
157+
158+
if self._all_done:
159+
return True
160+
161+
if update_name in self._background_update_queue:
162+
return False
163+
164+
update_exists = await self._simple_select_one_onecol(
165+
"background_updates",
166+
keyvalues={"update_name": update_name},
167+
retcol="1",
168+
desc="has_completed_background_update",
169+
allow_none=True,
170+
)
171+
172+
return not update_exists
173+
151174
@defer.inlineCallbacks
152175
def do_next_background_update(self, desired_duration_ms):
153176
"""Does some amount of work on the next queued background update

0 commit comments

Comments
 (0)