Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!(containers): remove ready status #742

Conversation

lusergit
Copy link
Collaborator

  • :ready and :stopped are redundant statuses, moved to using only :stopped status;
  • the check_deployment check when the deployment is available sets the deployment status tio the device deployment status

Copy link
Collaborator

@noaccOS noaccOS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're also missing the change on deployment_event: while we want to propagate a deployment error in any situation, we want to avoid setting starting/stopping while we're setting up the deployment, otherwise it will mess with the "state machine"

@lusergit lusergit changed the title fix(containers): remove ready status fix!(containers): remove ready status Nov 26, 2024
@lusergit lusergit requested a review from noaccOS November 26, 2024 11:51
Copy link
Collaborator

@davidebriani davidebriani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nitpicks, but the PR is good

@lusergit lusergit force-pushed the fix/ready-status branch 2 times, most recently from 8301164 to b25b1a1 Compare November 26, 2024 14:30
Comment on lines 214 to 217
_ ->
if deployment.status in @initial_statuses,
do: {:ok, deployment},
else: Containers.deployment_set_status(deployment, status, message, tenant: tenant)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the device is publishing the Stopped status when all resources are ready, we should update the deployment status to Stopped instead of doing nothing.

You consider using a cond statement here too:

with {:ok, deployment} <- Containers.fetch_deployment(deployment_id, tenant: tenant) do
  cond do
    status == "Starting" and deployment.status == :started ->
      # Skip Starting if already Started
      {:ok, deployment}

    status == "Stopping" and deployment.status == :stopped ->
      # Skip Stopping if already Stopped
      {:ok, deployment}
      
    status == "Error" ->
      # An error has occurred, set the deployment status immediately
      Containers.deployment_set_status(deployment, status, message, tenant: tenant)
      
    deployment.status in @initial_statuses ->
      # Besides errors, verify status of deployment resources before
      # blindly setting the deployment status. Indeed, a Stopped
      # status could be signaled before all resources are ready.
      Containers.deployment_update_status(deployment, tenant: tenant)
      
    true ->
      # Besides initial statuses, directly set the deployment status
      Containers.deployment_set_status(deployment, status, message, tenant: tenant)
  end
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On deployment event we can only receive starting or stopping, not stopped
If all resources are ready and we receive a stopped on available_deployments, the update_status will correctly set the status to stopped and run the callbacks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I just realized the same thing.

We could still consider the cond statement if it makes the code clearer and less nested.

Regarding the Stopped status, it probably doesn't do any harm calling Containers.deployment_update_status(deployment, tenant: tenant) here too. It might serves us well if we get the device to also publish Stopped on DeploymentEvents as we were discussing the other day (because that would fix the fact that the Stopped status property on AvailableDeployments is not re-sent from Astarte and would let us avoid having the first two cond cases).

Just food for thought, the current code already works.

- `:ready` and `:stopped` are redundant statuses, moved to using only
  `:stopped` status;
- the `check_deployment` check when the deployment is available sets the
  deployment status tio the device deployment status

Signed-off-by: Luca Zaninotto <[email protected]>
@noaccOS noaccOS merged commit 5abd8b6 into edgehog-device-manager:feature/application-management Nov 26, 2024
8 checks passed
@lusergit lusergit deleted the fix/ready-status branch December 2, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants