From fd8aad312aa093f83afe6dd6d19612b091172b04 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 22 Sep 2020 14:08:36 -0400 Subject: [PATCH] Accept a worker name instead of using a flag. --- docs/sample_config.yaml | 6 ++++++ synapse/config/workers.py | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/sample_config.yaml b/docs/sample_config.yaml index fb04ff283d..c95e49c3fe 100644 --- a/docs/sample_config.yaml +++ b/docs/sample_config.yaml @@ -2458,6 +2458,12 @@ opentracing: # events: worker1 # typing: worker1 +# The worker that is used to run background tasks (e.g. cleaning up expired +# data). This should be one of the workers from `instance_map`. If not +# provided this defaults to the main process. +# +#run_background_tasks: worker1 + # Configuration for Redis when using workers. This *must* be enabled when # using workers (unless using old style direct TCP configuration). diff --git a/synapse/config/workers.py b/synapse/config/workers.py index 3df07c83bd..1aff1f7aa9 100644 --- a/synapse/config/workers.py +++ b/synapse/config/workers.py @@ -140,7 +140,15 @@ class WorkerConfig(Config): # # Effort is not made to ensure only a single instance of these tasks is # running. - self.run_background_tasks = config.get("run_background_tasks", True) + instance = config.get("run_background_tasks_on") or "master" + if instance != "master" and instance not in self.instance_map: + raise ConfigError( + "Instance %r is configured to run background tasks but does not appear in `instance_map` config." + % (instance,) + ) + self.run_background_tasks = ( + self.worker_name is None and instance == "master" + ) or self.worker_name == instance def generate_config_section(self, config_dir_path, server_name, **kwargs): return """\ @@ -177,6 +185,12 @@ class WorkerConfig(Config): #stream_writers: # events: worker1 # typing: worker1 + + # The worker that is used to run background tasks (e.g. cleaning up expired + # data). This should be one of the workers from `instance_map`. If not + # provided this defaults to the main process. + # + #run_background_tasks: worker1 """ def read_arguments(self, args):