Skip to content

Commit

Permalink
style: improve from_stale_hosted_entities
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulFarault committed Nov 20, 2024
1 parent 15b44b5 commit 7046ec8
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions tdp/core/models/deployment_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,18 +360,15 @@ def from_stale_hosted_entities(
)
if len(operation_hosts) == 0:
raise NothingToReconfigureError("No component needs to be reconfigured.")

# Sort by hosts to improve readability
operation_hosts_sorted = sorted(
operation_hosts, key=lambda x: f"{x.operation_name}_{x.host_name}"
)

# Sort operations using DAG topological sort.
reconfigure_operations_sorted = Dag(collections).topological_sort_key(
operation_hosts_sorted = Dag(collections).topological_sort_key(
operation_hosts_sorted,
key=lambda x: x.operation_name.replace("_restart", "_start"),
)

# Generate deployment
deployment = DeploymentModel(
deployment_type=DeploymentTypeEnum.RECONFIGURE,
Expand All @@ -385,7 +382,7 @@ def from_stale_hosted_entities(
state=DeploymentStateEnum.PLANNED,
)
operation_order = 1
for operation, host in reconfigure_operations_sorted:
for operation, host in operation_hosts_sorted:
deployment.operations.append(
OperationModel(
operation=operation,
Expand All @@ -410,7 +407,6 @@ def from_stale_hosted_entities(
state=OperationStateEnum.PLANNED,
)
)

operation_order += 1
return deployment

Expand Down

0 comments on commit 7046ec8

Please sign in to comment.