diff options
author | Brendan Abolivier <babolivier@matrix.org> | 2020-01-21 19:04:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-21 19:04:58 +0000 |
commit | 07124d028df6b33336dcc2ef807fd7866f42902a (patch) | |
tree | 964a1540ad4eb30991e78a0b0144c215faa52ec7 /scripts-dev/update_database | |
parent | Add a DeltaState to track changes to be made to current state (#6716) (diff) | |
download | synapse-07124d028df6b33336dcc2ef807fd7866f42902a.tar.xz |
Port synapse_port_db to async/await (#6718)
* Raise an exception if there are pending background updates So we return with a non-0 code * Changelog * Port synapse_port_db to async/await * Port update_database to async/await * Add version string to mocked homeservers * Remove unused imports * Convert overseen bits to async/await * Fixup logging contexts * Fix imports * Add a way to print an error without raising an exception * Incorporate review
Diffstat (limited to '')
-rwxr-xr-x | scripts-dev/update_database | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/scripts-dev/update_database b/scripts-dev/update_database index 1d62f0403a..94aa8758b4 100755 --- a/scripts-dev/update_database +++ b/scripts-dev/update_database @@ -22,10 +22,12 @@ import yaml from twisted.internet import defer, reactor +import synapse from synapse.config.homeserver import HomeServerConfig from synapse.metrics.background_process_metrics import run_as_background_process from synapse.server import HomeServer from synapse.storage import DataStore +from synapse.util.versionstring import get_version_string logger = logging.getLogger("update_database") @@ -38,6 +40,8 @@ class MockHomeserver(HomeServer): config.server_name, reactor=reactor, config=config, **kwargs ) + self.version_string = "Synapse/"+get_version_string(synapse) + if __name__ == "__main__": parser = argparse.ArgumentParser( @@ -81,15 +85,17 @@ if __name__ == "__main__": hs.setup() store = hs.get_datastore() - @defer.inlineCallbacks - def run_background_updates(): - yield store.db.updates.run_background_updates(sleep=False) + async def run_background_updates(): + await store.db.updates.run_background_updates(sleep=False) # Stop the reactor to exit the script once every background update is run. reactor.stop() - # Apply all background updates on the database. - reactor.callWhenRunning( - lambda: run_as_background_process("background_updates", run_background_updates) - ) + def run(): + # Apply all background updates on the database. + defer.ensureDeferred( + run_as_background_process("background_updates", run_background_updates) + ) + + reactor.callWhenRunning(run) reactor.run() |