Skip to content

Commit 794d188

Browse files
giulio93lucarin91
andcommitted
Update internal/orchestrator/orchestrator.go
Co-authored-by: Luca Rinaldi <l.rinaldi@arduino.cc>
1 parent d60c60f commit 794d188

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

internal/api/handlers/app_delete.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import (
1919
"log/slog"
2020
"net/http"
2121

22+
"github.com/docker/cli/cli/command"
23+
2224
"github.com/arduino/arduino-app-cli/internal/api/models"
2325
"github.com/arduino/arduino-app-cli/internal/orchestrator"
2426
"github.com/arduino/arduino-app-cli/internal/orchestrator/app"
2527
"github.com/arduino/arduino-app-cli/internal/render"
26-
"github.com/docker/cli/cli/command"
2728
)
2829

2930
func HandleAppDelete(

internal/e2e/daemon/app_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ func TestDeleteApp(t *testing.T) {
438438
deleteResp, err := httpClient.DeleteApp(t.Context(), appToDeleteId)
439439
require.NoError(t, err)
440440
defer deleteResp.Body.Close()
441-
require.Equal(t, http.StatusOK, deleteResp.StatusCode)
441+
require.Equal(t, http.StatusInternalServerError, deleteResp.StatusCode)
442+
fmt.Println(deleteResp.Body)
442443

443444
getResp, err := httpClient.GetAppDetails(t.Context(), appToDeleteId)
444445
require.NoError(t, err)

internal/orchestrator/orchestrator.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func stopAppWithCmd(ctx context.Context, docker command.Cli, app app.ArduinoApp,
388388
return
389389
}
390390
if appStatus.Status != StatusStarting && appStatus.Status != StatusRunning {
391-
yield(StreamMessage{error: fmt.Errorf("App %q is not running", app.Name)})
391+
yield(StreamMessage{data: fmt.Sprintf("app %q is not running", app.Name)})
392392
return
393393
}
394394

@@ -406,7 +406,6 @@ func stopAppWithCmd(ctx context.Context, docker command.Cli, app app.ArduinoApp,
406406
}
407407
})
408408

409-
fmt.Printf("this is the main sketch path:%s", app.MainSketchPath)
410409
if app.MainSketchPath != nil {
411410
// TODO: check that the app sketch is running before attempting to stop it.
412411

@@ -901,11 +900,18 @@ func CloneApp(
901900
}
902901

903902
func DeleteApp(ctx context.Context, dockerClient command.Cli, app app.ArduinoApp) error {
904-
for msg := range StopApp(ctx, dockerClient, app) {
905-
if msg.error != nil {
906-
return fmt.Errorf("failed to stop app: %w", msg.error)
903+
904+
runningApp, err := getRunningApp(ctx, dockerClient.Client())
905+
if err != nil {
906+
return err
907+
}
908+
if runningApp != nil && runningApp.FullPath.EqualsTo(app.FullPath) {
909+
// We try to remove docker related resources at best effort
910+
for range StopAndDestroyApp(ctx, dockerClient, app) {
911+
// just consume the iterator
907912
}
908913
}
914+
909915
return app.FullPath.RemoveAll()
910916
}
911917

0 commit comments

Comments
 (0)