summary refs log tree commit diff
diff options
context:
space:
mode:
authorreivilibre <oliverw@matrix.org>2023-08-03 12:42:19 +0000
committerGitHub <noreply@github.com>2023-08-03 08:42:19 -0400
commit9c462f18a4b6969f627349d956b9161968ab8252 (patch)
tree2c0611d52c6576bbbe843a6a8a9f46e9187a21bd
parentAdd forward-compatibility for the redacts property (MSC2174). (#16013) (diff)
downloadsynapse-9c462f18a4b6969f627349d956b9161968ab8252.tar.xz
Allow modules to check whether the current worker is configured to run background tasks. (#15991)
-rw-r--r--changelog.d/15991.misc1
-rw-r--r--synapse/module_api/__init__.py12
2 files changed, 13 insertions, 0 deletions
diff --git a/changelog.d/15991.misc b/changelog.d/15991.misc
new file mode 100644

index 0000000000..18f388cff8 --- /dev/null +++ b/changelog.d/15991.misc
@@ -0,0 +1 @@ +Allow modules to check whether the current worker is configured to run background tasks. \ No newline at end of file diff --git a/synapse/module_api/__init__.py b/synapse/module_api/__init__.py
index 95f7800111..ba1a925003 100644 --- a/synapse/module_api/__init__.py +++ b/synapse/module_api/__init__.py
@@ -1230,6 +1230,18 @@ class ModuleApi: f, ) + def should_run_background_tasks(self) -> bool: + """ + Return true if and only if the current worker is configured to run + background tasks. + There should only be one worker configured to run background tasks, so + this is helpful when you need to only run a task on one worker but don't + have any other good way to choose which one. + + Added in Synapse v1.89.0. + """ + return self._hs.config.worker.run_background_tasks + async def sleep(self, seconds: float) -> None: """Sleeps for the given number of seconds.