Allow modules to check whether the current worker is configured to run background tasks. (#15991)

pull/16061/head
reivilibre 2023-08-03 12:42:19 +00:00 committed by GitHub
parent 4f5bccbbba
commit 9c462f18a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

1
changelog.d/15991.misc Normal file
View File

@ -0,0 +1 @@
Allow modules to check whether the current worker is configured to run background tasks.

View File

@ -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.