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

Allow modules to run only on specific worker(s) #10701

@anoadragon453

Description

@anoadragon453

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-EnhancementNew features, changes in functionality, improvements in performance, or user-facing enhancements.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions