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 3c2f3d3 commit e0c4cb3
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions tdp/core/models/deployment_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,14 @@ 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(
# Sort operations using DAG topological sort
operation_hosts_sorted = Dag(collections).topological_sort_key(
operation_hosts_sorted, key=lambda x: x.operation.name
)

# Generate deployment
deployment = DeploymentModel(
deployment_type=DeploymentTypeEnum.RECONFIGURE,
Expand All @@ -384,7 +381,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.name,
Expand All @@ -406,7 +403,6 @@ def from_stale_hosted_entities(
state=OperationStateEnum.PLANNED,
)
)

operation_order += 1
return deployment

Expand Down

0 comments on commit e0c4cb3

Please sign in to comment.