Skip to content

Commit

Permalink
feat: update deployment and operation status during
Browse files Browse the repository at this point in the history
iteration
  • Loading branch information
PaulFarault committed Nov 8, 2023
1 parent 99de038 commit 3becc90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tdp/cli/commands/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ def deploy(

# deployment and operations records are mutated by the iterator so we need to
# commit them before iterating and at each iteration
session.commit() # Update deployment status to RUNNING
session.commit() # Update deployment status to RUNNING, operations to PENDING
for cluster_status_logs in deployment_iterator:
session.commit() # Update operation status to RUNNING
if cluster_status_logs and any(cluster_status_logs):
session.add_all(cluster_status_logs)
session.commit()
session.commit() # Update operation status to SUCCESS, FAILURE or HELD

if deployment_iterator.deployment.status != DeploymentStateEnum.SUCCESS:
raise click.ClickException("Deployment failed.")
Expand Down
5 changes: 5 additions & 0 deletions tdp/core/deployment/deployment_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ def __init__(
cluster_variables: ClusterVariables instance.
cluster_status: ClusterStatus instance.
"""
# Initialize the deployment state
self.deployment = deployment
self.deployment.start_time = datetime.utcnow()
for operation in deployment.operations:
operation.state = OperationStateEnum.PENDING
# Initialize the iterator
self._cluster_status = cluster_status
self._collections = collections
Expand Down Expand Up @@ -112,6 +115,8 @@ def __next__(self) -> Optional[list[SCHStatusLogModel]]:
if self.deployment.status == DeploymentStateEnum.FAILURE:
operation_rec.state = OperationStateEnum.HELD
return
else:
operation_rec.state = OperationStateEnum.RUNNING

# Retrieve operation to access parsed attributes and playbook
operation = self._collections.get_operation(operation_rec.operation)
Expand Down

0 comments on commit 3becc90

Please sign in to comment.