mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-25 00:29:22 -05:00
Allow modules to run looping call on all instances (#10638)
By default the calls only ran on the worker configured to run background tasks.
This commit is contained in:
parent
703e3a9e85
commit
5581dd7bf7
1
changelog.d/10638.feature
Normal file
1
changelog.d/10638.feature
Normal file
@ -0,0 +1 @@
|
|||||||
|
Add option to allow modules to run periodic tasks on all instances, rather than just the one configured to run background tasks.
|
@ -604,10 +604,15 @@ class ModuleApi:
|
|||||||
msec: float,
|
msec: float,
|
||||||
*args,
|
*args,
|
||||||
desc: Optional[str] = None,
|
desc: Optional[str] = None,
|
||||||
|
run_on_all_instances: bool = False,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""Wraps a function as a background process and calls it repeatedly.
|
"""Wraps a function as a background process and calls it repeatedly.
|
||||||
|
|
||||||
|
NOTE: Will only run on the instance that is configured to run
|
||||||
|
background processes (which is the main process by default), unless
|
||||||
|
`run_on_all_workers` is set.
|
||||||
|
|
||||||
Waits `msec` initially before calling `f` for the first time.
|
Waits `msec` initially before calling `f` for the first time.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -618,12 +623,14 @@ class ModuleApi:
|
|||||||
msec: How long to wait between calls in milliseconds.
|
msec: How long to wait between calls in milliseconds.
|
||||||
*args: Positional arguments to pass to function.
|
*args: Positional arguments to pass to function.
|
||||||
desc: The background task's description. Default to the function's name.
|
desc: The background task's description. Default to the function's name.
|
||||||
|
run_on_all_instances: Whether to run this on all instances, rather
|
||||||
|
than just the instance configured to run background tasks.
|
||||||
**kwargs: Key arguments to pass to function.
|
**kwargs: Key arguments to pass to function.
|
||||||
"""
|
"""
|
||||||
if desc is None:
|
if desc is None:
|
||||||
desc = f.__name__
|
desc = f.__name__
|
||||||
|
|
||||||
if self._hs.config.run_background_tasks:
|
if self._hs.config.run_background_tasks or run_on_all_instances:
|
||||||
self._clock.looping_call(
|
self._clock.looping_call(
|
||||||
run_as_background_process,
|
run_as_background_process,
|
||||||
msec,
|
msec,
|
||||||
|
Loading…
Reference in New Issue
Block a user