-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow modules to run only on specific worker(s) #10701
Description
There are some usecases for wanting a Synapse module to execute functionality once when it is running on a specific worker. Usecases include:
- A module that auto-accepts invites for certain users. Accepting the invite should only be done by a single instance of the module - not all of them at once.
- A module that wishes to send presence to other modules. This should only be done by one instance of a module (to avoid sending duplicate presence), and should only be done on workers that support sending federation traffic.
To achieve this, it is sometimes suggested to add worker-specific config for a module, in order to tell a module running on one worker to carry out a task, but to not do the same for the module config on other workers.
This method is fragile though - not least because you may wish to share module config between all worker instances, and having to have separate config per-worker is overhead to manage. Additionally, because homeserver config keys are overwritten when specifying multiple homeserver config files (as is commonly done with workers), you can't really configure a worker in one way on the main process, and in a subtly different way on the worker. The worker's config will need to be entirely duplicated.
As a proposed solution, we simply make the worker's name (None if the main process) available to modules. That way, we could simply state in the module's config that certain functionality should only run if the name of the worker that the module is running on matches against some configured value(s).