Skip to content

Commit aee844d

Browse files
committed
feat: reconcile on retry
When a user retries to deploy an application, some feedback is needed. It might happen that some triggers were not recived/handled properly on our side, and therefore the deployment remains not sent until an automatica reconciliation happens much later. This change adds a manual reconicliation if a user requests a resend, this way unhandled triggers are still considered. Signed-off-by: Luca Zaninotto <luca.zaninotto@secomind.com>
1 parent 8ebf984 commit aee844d

5 files changed

Lines changed: 70 additions & 2 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# SPDX-FileCopyrightText: 2021 SECO Mind Srl
1+
# SPDX-FileCopyrightText: 2021-2026 SECO Mind Srl
22
# SPDX-License-Identifier: CC0-1.0
33

44
# Ignore local emacs variables
55
/.dir-locals.el
6+
/.dexter.db*

backend/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ edgehog-*.tar
3838
# Ignore expert lsp files
3939
/.expert
4040

41+
# dexter lsp
42+
/.dexter.db*
43+
4144
# ProtoBuf compilation dependencies
4245
/priv/api/
4346
/priv/googleapis/

backend/lib/edgehog/containers/containers.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ defmodule Edgehog.Containers do
173173
update Deployment, :start_deployment, :start
174174
update Deployment, :stop_deployment, :stop
175175
update Deployment, :delete_deployment, :delete
176-
update Deployment, :send_deployment, :send_deployment
176+
update Deployment, :send_deployment, :retry_deployment
177177

178178
update Deployment, :upgrade_deployment, :upgrade_release do
179179
relay_id_translations input: [target: :release]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# This file is part of Edgehog.
3+
#
4+
# Copyright 2026 SECO Mind Srl
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#
20+
21+
defmodule Edgehog.Containers.Deployment.Changes.Reconcile do
22+
@moduledoc """
23+
Starts a reconciliation with the device.
24+
25+
Careful: this implies querying appengine, it can be traffic intensive.
26+
"""
27+
use Ash.Resource.Change
28+
29+
alias Edgehog.Containers.Reconciler
30+
31+
require Logger
32+
33+
@impl Ash.Resource.Change
34+
def change(changeset, _opts, %{tenant: tenant}) do
35+
deployment = Ash.load!(changeset.data, :device, tenant: tenant)
36+
device = deployment.device
37+
device_id = device.id
38+
39+
Ash.Changeset.after_transaction(changeset, &after_transaction(&1, &2, device_id, tenant))
40+
end
41+
42+
defp after_transaction(_changeset, {:ok, _resource} = result, device_id, tenant) do
43+
args = %{device_id: device_id, tenant: tenant}
44+
45+
Reconciler.Core.reconcile(args)
46+
47+
result
48+
end
49+
50+
defp after_transaction(_changeset, result, _device_id, _tenant), do: result
51+
end

backend/lib/edgehog/containers/deployment/deployment.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ defmodule Edgehog.Containers.Deployment do
175175
change Changes.SendDeploymentToDevice
176176
end
177177

178+
update :retry_deployment do
179+
description """
180+
Sends the deployment to the device.
181+
Deploys the necessary resources and sends the deployment request.
182+
"""
183+
184+
require_atomic? false
185+
186+
validate {Validations.IsReady, [readiness: false]}
187+
change Changes.SendDeploymentToDevice
188+
change Changes.Reconcile
189+
end
190+
178191
update :upgrade_release do
179192
argument :target, :uuid do
180193
allow_nil? false

0 commit comments

Comments
 (0)