summary refs log tree commit diff
path: root/synapse/config
diff options
context:
space:
mode:
authorPatrick Cloke <clokep@users.noreply.github.com>2020-10-02 08:23:15 -0400
committerGitHub <noreply@github.com>2020-10-02 08:23:15 -0400
commit62894673e69f7beb0d0a748ad01c2e95c5fed106 (patch)
treef3f70c95bc635045e833f8a62e1572258dee3bf9 /synapse/config
parentMerge tag 'v1.21.0rc2' into develop (diff)
downloadsynapse-62894673e69f7beb0d0a748ad01c2e95c5fed106.tar.xz
Allow background tasks to be run on a separate worker. (#8369)
Diffstat (limited to 'synapse/config')
-rw-r--r--synapse/config/workers.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/synapse/config/workers.py b/synapse/config/workers.py
index f23e42cdf9..57ab097eba 100644
--- a/synapse/config/workers.py
+++ b/synapse/config/workers.py
@@ -132,6 +132,19 @@ class WorkerConfig(Config):
 
         self.events_shard_config = ShardedWorkerHandlingConfig(self.writers.events)
 
+        # Whether this worker should run background tasks or not.
+        #
+        # As a note for developers, the background tasks guarded by this should
+        # 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.
+        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
+
     def generate_config_section(self, config_dir_path, server_name, **kwargs):
         return """\
         ## Workers ##
@@ -167,6 +180,11 @@ class WorkerConfig(Config):
         #stream_writers:
         #  events: worker1
         #  typing: worker1
+
+        # The worker that is used to run background tasks (e.g. cleaning up expired
+        # data). If not provided this defaults to the main process.
+        #
+        #run_background_tasks_on: worker1
         """
 
     def read_arguments(self, args):