mirror of
https://github.com/element-hq/synapse
synced 2024-09-29 00:42:45 +00:00
Fix comment and mutation bug on merge_worker_template_configs
This commit is contained in:
parent
259a808dc2
commit
3a46cf08e9
1 changed files with 22 additions and 31 deletions
|
@ -420,43 +420,34 @@ def add_worker_to_instance_map(
|
||||||
|
|
||||||
|
|
||||||
def merge_worker_template_configs(
|
def merge_worker_template_configs(
|
||||||
existing_template: WorkerTemplate,
|
left: WorkerTemplate,
|
||||||
to_be_merged_template: WorkerTemplate,
|
right: WorkerTemplate,
|
||||||
) -> WorkerTemplate:
|
) -> WorkerTemplate:
|
||||||
"""When given an existing dict of worker template configuration consisting with both
|
"""Merges two templates together, returning a new template that includes
|
||||||
dicts and lists, merge new template data from WORKERS_CONFIG(or create) and
|
the listeners, endpoint patterns and configuration from both.
|
||||||
return new dict.
|
|
||||||
|
|
||||||
Args:
|
Does not mutate the input templates.
|
||||||
existing_template: Either an existing worker template or a fresh blank one.
|
|
||||||
to_be_merged_template: The template from WORKERS_CONFIGS to be merged into
|
|
||||||
existing_dict.
|
|
||||||
Returns: The newly merged together dict values.
|
|
||||||
"""
|
"""
|
||||||
# copy existing_template without any replacements
|
|
||||||
new_template: WorkerTemplate = dataclasses.replace(existing_template)
|
|
||||||
|
|
||||||
# add listener resources from the other set
|
return WorkerTemplate(
|
||||||
new_template.listener_resources |= to_be_merged_template.listener_resources
|
# include listener resources from both
|
||||||
|
listener_resources=left.listener_resources | right.listener_resources,
|
||||||
# add endpoint patterns from the other set
|
# include endpoint patterns from both
|
||||||
new_template.endpoint_patterns |= to_be_merged_template.endpoint_patterns
|
endpoint_patterns=left.endpoint_patterns | right.endpoint_patterns,
|
||||||
|
# merge shared config dictionaries; the worker name will be replaced later
|
||||||
# merge dictionaries; the worker name will be replaced later
|
shared_extra_conf=lambda worker_name: merged(
|
||||||
new_template.shared_extra_conf = lambda worker_name: merged(
|
left.shared_extra_conf(worker_name),
|
||||||
existing_template.shared_extra_conf(worker_name),
|
right.shared_extra_conf(worker_name),
|
||||||
to_be_merged_template.shared_extra_conf(worker_name),
|
),
|
||||||
|
# There is only one worker type that has a 'worker_extra_conf' and it is
|
||||||
|
# the media_repo. Since duplicate worker types on the same worker don't
|
||||||
|
# work, this is fine.
|
||||||
|
worker_extra_conf=(left.worker_extra_conf + right.worker_extra_conf),
|
||||||
|
# (This is unused, but in principle sharding this hybrid worker type
|
||||||
|
# would be allowed if both constituent types are shardable)
|
||||||
|
sharding_allowed=left.sharding_allowed and right.sharding_allowed,
|
||||||
)
|
)
|
||||||
|
|
||||||
# There is only one worker type that has a 'worker_extra_conf' and it is
|
|
||||||
# the media_repo. Since duplicate worker types on the same worker don't
|
|
||||||
# work, this is fine.
|
|
||||||
new_template.worker_extra_conf = (
|
|
||||||
new_template.worker_extra_conf + to_be_merged_template.worker_extra_conf
|
|
||||||
)
|
|
||||||
|
|
||||||
return new_template
|
|
||||||
|
|
||||||
|
|
||||||
def insert_worker_name_for_worker_config(
|
def insert_worker_name_for_worker_config(
|
||||||
existing_template: WorkerTemplate, worker_name: str
|
existing_template: WorkerTemplate, worker_name: str
|
||||||
|
|
Loading…
Reference in a new issue