From 7470051bc4093a8e93cac2f1be0a28f64141e174 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 31 Jan 2022 18:39:10 +0000 Subject: [PATCH 1/2] Allow modules to retrieve server and worker names --- changelog.d/11868.feature | 1 + synapse/module_api/__init__.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 changelog.d/11868.feature diff --git a/changelog.d/11868.feature b/changelog.d/11868.feature new file mode 100644 index 000000000000..3723dac4ea10 --- /dev/null +++ b/changelog.d/11868.feature @@ -0,0 +1 @@ +Allow modules to retrieve the current instance's server name and worker name. diff --git a/synapse/module_api/__init__.py b/synapse/module_api/__init__.py index 788b2e47d523..778c5cd57d4c 100644 --- a/synapse/module_api/__init__.py +++ b/synapse/module_api/__init__.py @@ -401,6 +401,23 @@ def email_app_name(self) -> str: """ return self._hs.config.email.email_app_name + @property + def server_name(self) -> str: + """The server name for the local homeserver. + + Added in Synapse v1.53.0. + """ + return self._server_name + + @property + def worker_name(self) -> Optional[str]: + """The name of the worker this specific instance is running as per the + "worker_app" configuration setting, or None if it's the main process. + + Added in Synapse v1.53.0. + """ + return self._hs.config.worker.worker_app + async def get_userinfo_by_id(self, user_id: str) -> Optional[UserInfo]: """Get user info by user_id From a6a9cdeaa3bebab38f0345cb4f4e3ffca1f7df31 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 31 Jan 2022 19:17:28 +0000 Subject: [PATCH 2/2] Also expose worker_app --- synapse/module_api/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/synapse/module_api/__init__.py b/synapse/module_api/__init__.py index 778c5cd57d4c..29fbc73c971d 100644 --- a/synapse/module_api/__init__.py +++ b/synapse/module_api/__init__.py @@ -412,6 +412,15 @@ def server_name(self) -> str: @property def worker_name(self) -> Optional[str]: """The name of the worker this specific instance is running as per the + "worker_name" configuration setting, or None if it's the main process. + + Added in Synapse v1.53.0. + """ + return self._hs.config.worker.worker_name + + @property + def worker_app(self) -> Optional[str]: + """The name of the worker app this specific instance is running as per the "worker_app" configuration setting, or None if it's the main process. Added in Synapse v1.53.0.