diff options
author | Erik Johnston <erik@matrix.org> | 2016-01-28 14:45:36 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-01-28 14:45:36 +0000 |
commit | 167d1df699d64683f1f9ace759c772af1890ca56 (patch) | |
tree | a9222f66b36c828df5ca2fcd455db820dcd80dca /synapse/app | |
parent | Quot all the things (diff) | |
parent | Clean up a bit. Add comment (diff) | |
download | synapse-167d1df699d64683f1f9ace759c772af1890ca56.tar.xz |
Merge pull request #534 from matrix-org/erikj/setup
Add a Homeserver.setup method
Diffstat (limited to 'synapse/app')
-rwxr-xr-x | synapse/app/homeserver.py | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index a83d3f394f..e5066c48ef 100755 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -254,6 +254,18 @@ class SynapseHomeServer(HomeServer): except IncorrectDatabaseSetup as e: quit_with_error(e.message) + def get_db_conn(self): + # Any param beginning with cp_ is a parameter for adbapi, and should + # not be passed to the database engine. + db_params = { + k: v for k, v in self.db_config.get("args", {}).items() + if not k.startswith("cp_") + } + db_conn = self.database_engine.module.connect(**db_params) + + self.database_engine.on_new_connection(db_conn) + return db_conn + def quit_with_error(error_string): message_lines = error_string.split("\n") @@ -390,13 +402,7 @@ def setup(config_options): logger.info("Preparing database: %s...", config.database_config['name']) try: - db_conn = database_engine.module.connect( - **{ - k: v for k, v in config.database_config.get("args", {}).items() - if not k.startswith("cp_") - } - ) - + db_conn = hs.get_db_conn() database_engine.prepare_database(db_conn) hs.run_startup_checks(db_conn, database_engine) @@ -411,13 +417,17 @@ def setup(config_options): logger.info("Database prepared in %s.", config.database_config['name']) + hs.setup() hs.start_listening() - hs.get_pusherpool().start() - hs.get_state_handler().start_caching() - hs.get_datastore().start_profiling() - hs.get_datastore().start_doing_background_updates() - hs.get_replication_layer().start_get_pdu_cache() + def start(): + hs.get_pusherpool().start() + hs.get_state_handler().start_caching() + hs.get_datastore().start_profiling() + hs.get_datastore().start_doing_background_updates() + hs.get_replication_layer().start_get_pdu_cache() + + reactor.callWhenRunning(start) return hs |