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

Port synapse_port_db to async/await #6718

Merged
merged 12 commits into from
Jan 21, 2020
1 change: 1 addition & 0 deletions changelog.d/6718.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug causing the `synapse_port_db` script to return 0 in a specific error case.
20 changes: 13 additions & 7 deletions scripts-dev/update_database
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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(
Expand Down Expand Up @@ -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()
Loading