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

Commit 5581dd7

Browse files
authored
Allow modules to run looping call on all instances (#10638)
By default the calls only ran on the worker configured to run background tasks.
1 parent 703e3a9 commit 5581dd7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

changelog.d/10638.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add option to allow modules to run periodic tasks on all instances, rather than just the one configured to run background tasks.

synapse/module_api/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,15 @@ def looping_background_call(
604604
msec: float,
605605
*args,
606606
desc: Optional[str] = None,
607+
run_on_all_instances: bool = False,
607608
**kwargs,
608609
):
609610
"""Wraps a function as a background process and calls it repeatedly.
610611
612+
NOTE: Will only run on the instance that is configured to run
613+
background processes (which is the main process by default), unless
614+
`run_on_all_workers` is set.
615+
611616
Waits `msec` initially before calling `f` for the first time.
612617
613618
Args:
@@ -618,12 +623,14 @@ def looping_background_call(
618623
msec: How long to wait between calls in milliseconds.
619624
*args: Positional arguments to pass to function.
620625
desc: The background task's description. Default to the function's name.
626+
run_on_all_instances: Whether to run this on all instances, rather
627+
than just the instance configured to run background tasks.
621628
**kwargs: Key arguments to pass to function.
622629
"""
623630
if desc is None:
624631
desc = f.__name__
625632

626-
if self._hs.config.run_background_tasks:
633+
if self._hs.config.run_background_tasks or run_on_all_instances:
627634
self._clock.looping_call(
628635
run_as_background_process,
629636
msec,

0 commit comments

Comments
 (0)