Skip to content

Commit b6723a5

Browse files
authored
fix: force app stop also if it isn't running (#112)
1 parent 299f6e2 commit b6723a5

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

internal/orchestrator/orchestrator.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -388,16 +388,6 @@ func stopAppWithCmd(ctx context.Context, docker command.Cli, app app.ArduinoApp,
388388
ctx, cancel := context.WithCancel(ctx)
389389
defer cancel()
390390

391-
appStatus, err := getAppStatus(ctx, docker, app)
392-
if err != nil {
393-
yield(StreamMessage{error: err})
394-
return
395-
}
396-
if appStatus.Status != StatusStarting && appStatus.Status != StatusRunning {
397-
yield(StreamMessage{data: fmt.Sprintf("app %q is not running", app.Name)})
398-
return
399-
}
400-
401391
if !yield(StreamMessage{data: fmt.Sprintf("Stopping app %q", app.Name)}) {
402392
return
403393
}
@@ -413,7 +403,16 @@ func stopAppWithCmd(ctx context.Context, docker command.Cli, app app.ArduinoApp,
413403
})
414404

415405
if app.MainSketchPath != nil {
416-
// TODO: check that the app sketch is running before attempting to stop it.
406+
// Before stopping the microcontroller we want to make sure that the app was running.
407+
appStatus, err := getAppStatus(ctx, docker, app)
408+
if err != nil {
409+
yield(StreamMessage{error: err})
410+
return
411+
}
412+
if appStatus.Status != StatusStarting && appStatus.Status != StatusRunning {
413+
yield(StreamMessage{data: fmt.Sprintf("app %q is not running", app.Name)})
414+
return
415+
}
417416

418417
if err := micro.Disable(); err != nil {
419418
yield(StreamMessage{error: err})

0 commit comments

Comments
 (0)