-
-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Make media_repo be a generic_worker
Quoted from the modernize configure workers script PR:
- For Details 1:
synapse.app.media_repository
is asynapse.app.generic_worker
, however because of this line,enable_media_repo
won't work withsynapse.app.generic_worker
. As such, this won't be changed now. I feel like this logic should be in the workers.py file with similar type options(likerun_background_tasks_on
,notify_appservices_from_worker
andupdate_user_directory_from_worker
), and possibly adapted to use_should_this_worker_perform_duty()
. Ideally, this should all be on a map instance that hashes byworker_name
in the shared config.
Having looked into this a bit more, it's slightly more involved than a simple removal.
Things we know:
-
In:
synapse-unraid/synapse/config/server.py
Lines 350 to 355 in fdb36e0
# whether to enable the media repository endpoints. This should be set # to false if the media repository is running as a separate endpoint; # doing so ensures that we will not run cache cleanup jobs on the # master, potentially causing inconsistency. self.enable_media_repo = config.get("enable_media_repo", True)
setup looks forenable_media_repo
in the yaml, sets toTrue
by default, and adds it to theserver
section of ConfigObject. -
It is then passed into
/config/repository.py
at:
synapse-unraid/synapse/config/repository.py
Lines 120 to 130 in fdb36e0
# Only enable the media repo if either the media repo is enabled or the # current worker app is the media repo. if ( self.root.server.enable_media_repo is False and config.get("worker_app") != "synapse.app.media_repository" ): self.can_load_media_repo = False return else: self.can_load_media_repo = True
wherecan_load_media_repo
is set for that single instance(in this case a worker). If set toTrue
then it enables the endpoint processing for media bits, according to comments in the source (included in "thing 1 above) also prevents cache cleanup inappropriately on master. Then it's added to themedia
section of the ConfigObject. -
can_load_media_repo
(specifically,(hs.config.|self.config|config.)media.can_load_media_repo
) is then used in potentially four other files. I think that's far enough for the purpose of this issue. This will be the last place to search for "True" or "False".
synapse/rest/admin/__init__.py
synapse/app/generic_worker.py
synapse/app/_base.py
synapse/rest/media/v1/media_repository.py
- Further, there is the option at this line that looks for
media_instance_running_background_jobs
and assigns that worker_name to handle those tasks(which I believe is only url previews presently?)
After pondering about this for a few days, I've come to the conclusion that there are two possible paths forward in order to remove synapse.app.media_repository
from the source in "Thing 2" above. It will still need a yaml setting of some kind so that the worker knows it will be responsible for handling the media repo.
- There is a similar setting already existing that can be placed in the worker yaml to handle this,
enable_media_repo
. Right now, this is used to explicitly disable the media functions on master(and other workers). I think if it's put into the worker yaml fragment, that will be appropriate. Logic will have to be added to look for this, I recommend inrepository.py
next to the existing logic, for backwards compatibility. - Build a new instance style map, similar to
pusher_instances
andfederation_sender_instances
. A quick mockup would look like:
media_repo_instances:
- media_repository1
Bonus to this approach would be that there would be no need for an enable_media_repo
setting in potentially more than two other yaml files, it could be in either homeserver.yaml or shared.yaml. Additional opportunity exists to add the media_instance_running_background_jobs
function to this at the same time and kill two birds with one stone.
Additional questions:
- Why is
enable_media_repo
in the server config section? Would it be more consistent to have it in workers?