Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Allow modules to check whether the current worker is configured to ru…
Browse files Browse the repository at this point in the history
…n background tasks. (#15991)
  • Loading branch information
reivilibre authored Aug 3, 2023
1 parent 4f5bccb commit 9c462f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/15991.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow modules to check whether the current worker is configured to run background tasks.
12 changes: 12 additions & 0 deletions synapse/module_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,18 @@ def looping_background_call(
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.
Expand Down

0 comments on commit 9c462f1

Please sign in to comment.