diff --git a/docs/sample_config.yaml b/docs/sample_config.yaml index aeebcaf45f..7f94911dbf 100644 --- a/docs/sample_config.yaml +++ b/docs/sample_config.yaml @@ -2766,6 +2766,11 @@ opentracing: # #run_background_tasks_on: worker1 +# The worker that is used to notify application services of new traffic within +# their configured namespace. If not provided this defaults to the main process. +# +#notify_appservices_from_worker: worker2 + # A shared secret used by the replication APIs to authenticate HTTP requests # from workers. # diff --git a/synapse/app/generic_worker.py b/synapse/app/generic_worker.py index 3b7131af8f..080f3e039d 100644 --- a/synapse/app/generic_worker.py +++ b/synapse/app/generic_worker.py @@ -427,22 +427,6 @@ def start(config_options): "synapse.app.user_dir", ) - if config.worker_app == "synapse.app.appservice": - if config.appservice.notify_appservices: - sys.stderr.write( - "\nThe appservices must be disabled in the main synapse process" - "\nbefore they can be run in a separate worker." - "\nPlease add ``notify_appservices: false`` to the main config" - "\n" - ) - sys.exit(1) - - # Force the appservice to start since they will be disabled in the main config - config.appservice.notify_appservices = True - else: - # For other worker types we force this to off. - config.appservice.notify_appservices = False - if config.worker_app == "synapse.app.user_dir": if config.server.update_user_directory: sys.stderr.write( diff --git a/synapse/config/appservice.py b/synapse/config/appservice.py index 1ebea88db2..313ee48247 100644 --- a/synapse/config/appservice.py +++ b/synapse/config/appservice.py @@ -32,7 +32,6 @@ class AppServiceConfig(Config): def read_config(self, config, **kwargs): self.app_service_config_files = config.get("app_service_config_files", []) - self.notify_appservices = config.get("notify_appservices", True) self.track_appservice_user_ips = config.get("track_appservice_user_ips", False) def generate_config_section(cls, **kwargs): diff --git a/synapse/config/workers.py b/synapse/config/workers.py index 462630201d..f6679e4466 100644 --- a/synapse/config/workers.py +++ b/synapse/config/workers.py @@ -275,13 +275,26 @@ class WorkerConfig(Config): # be able to run on only a single instance (meaning that they don't # depend on any in-memory state of a particular worker). # - # No effort is made to ensure only a single instance of these tasks is - # running. + # No effort is made here to ensure only a single instance of these tasks + # are running. background_tasks_instance = config.get("run_background_tasks_on") or "master" self.run_background_tasks = ( self.worker_name is None and background_tasks_instance == "master" ) or self.worker_name == background_tasks_instance + # Whether this worker should notify appservices of traffic within their namespace. + # + # As a note for developers, this task is currently not shardable, and thus should + # only be handled by a single process. + # + # No effort is made here to ensure only a single instance of this task running. + notify_appservices_instance = ( + config.get("notify_appservices_from_worker") or "master" + ) + self.should_notify_appservices = ( + self.worker_name is None and notify_appservices_instance == "master" + ) or self.worker_name == notify_appservices_instance + def generate_config_section(self, config_dir_path, server_name, **kwargs): return """\ ## Workers ## @@ -323,6 +336,11 @@ class WorkerConfig(Config): # #run_background_tasks_on: worker1 + # The worker that is used to notify application services of new traffic within + # their configured namespace. If not provided this defaults to the main process. + # + #notify_appservices_from_worker: worker2 + # A shared secret used by the replication APIs to authenticate HTTP requests # from workers. # diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py index 4ab4046650..2e89436772 100644 --- a/synapse/handlers/appservice.py +++ b/synapse/handlers/appservice.py @@ -52,7 +52,7 @@ class ApplicationServicesHandler: self.scheduler = hs.get_application_service_scheduler() self.started_scheduler = False self.clock = hs.get_clock() - self.notify_appservices = hs.config.notify_appservices + self.notify_appservices = hs.config.worker.should_notify_appservices self.event_sources = hs.get_event_sources() self.current_max = 0