workers.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 matrix.org
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from ._base import Config
  16. class WorkerConfig(Config):
  17. """The workers are processes run separately to the main synapse process.
  18. They have their own pid_file and listener configuration. They use the
  19. replication_url to talk to the main synapse process."""
  20. def read_config(self, config):
  21. self.worker_app = config.get("worker_app")
  22. # Canonicalise worker_app so that master always has None
  23. if self.worker_app == "synapse.app.homeserver":
  24. self.worker_app = None
  25. self.worker_listeners = config.get("worker_listeners")
  26. self.worker_daemonize = config.get("worker_daemonize")
  27. self.worker_pid_file = config.get("worker_pid_file")
  28. self.worker_log_file = config.get("worker_log_file")
  29. self.worker_log_config = config.get("worker_log_config")
  30. # The host used to connect to the main synapse
  31. self.worker_replication_host = config.get("worker_replication_host", None)
  32. # The port on the main synapse for TCP replication
  33. self.worker_replication_port = config.get("worker_replication_port", None)
  34. # The port on the main synapse for HTTP replication endpoint
  35. self.worker_replication_http_port = config.get("worker_replication_http_port")
  36. self.worker_name = config.get("worker_name", self.worker_app)
  37. self.worker_main_http_uri = config.get("worker_main_http_uri", None)
  38. self.worker_cpu_affinity = config.get("worker_cpu_affinity")
  39. if self.worker_listeners:
  40. for listener in self.worker_listeners:
  41. bind_address = listener.pop("bind_address", None)
  42. bind_addresses = listener.setdefault("bind_addresses", [])
  43. if bind_address:
  44. bind_addresses.append(bind_address)
  45. elif not bind_addresses:
  46. bind_addresses.append('')