Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 996d440

Browse files
chore: recreate -> create with argument
1 parent 3714fec commit 996d440

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

agent/agentcontainers/api.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ func (api *API) handleDevcontainerRecreate(w http.ResponseWriter, r *http.Reques
920920
api.knownDevcontainers[dc.WorkspaceFolder] = dc
921921
api.asyncWg.Add(1)
922922
go func() {
923-
_ = api.recreateDevcontainer(dc, configPath)
923+
_ = api.createDevcontainer(dc, configPath, true)
924924
}()
925925

926926
api.mu.Unlock()
@@ -939,17 +939,17 @@ func (api *API) CreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer) error
939939
api.asyncWg.Add(1)
940940
api.mu.Unlock()
941941

942-
return api.recreateDevcontainer(dc, dc.ConfigPath)
942+
return api.createDevcontainer(dc, dc.ConfigPath, false)
943943
}
944944

945-
// recreateDevcontainer should run in its own goroutine and is responsible for
945+
// createDevcontainer should run in its own goroutine and is responsible for
946946
// recreating a devcontainer based on the provided devcontainer configuration.
947947
// It updates the devcontainer status and logs the process. The configPath is
948948
// passed as a parameter for the odd chance that the container being recreated
949949
// has a different config file than the one stored in the devcontainer state.
950950
// The devcontainer state must be set to starting and the asyncWg must be
951951
// incremented before calling this function.
952-
func (api *API) recreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, configPath string) error {
952+
func (api *API) createDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, configPath string, restart bool) error {
953953
defer api.asyncWg.Done()
954954

955955
var (
@@ -991,12 +991,17 @@ func (api *API) recreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, con
991991

992992
logger.Debug(ctx, "starting devcontainer recreation")
993993

994-
_, err = api.dccli.Up(ctx, dc.WorkspaceFolder, configPath, WithUpOutput(infoW, errW), WithRemoveExistingContainer())
994+
upOptions := []DevcontainerCLIUpOptions{WithUpOutput(infoW, errW)}
995+
if restart {
996+
upOptions = append(upOptions, WithRemoveExistingContainer())
997+
}
998+
999+
_, err = api.dccli.Up(ctx, dc.WorkspaceFolder, configPath, upOptions...)
9951000
if err != nil {
9961001
// No need to log if the API is closing (context canceled), as this
9971002
// is expected behavior when the API is shutting down.
9981003
if !errors.Is(err, context.Canceled) {
999-
logger.Error(ctx, "devcontainer recreation failed", slog.Error(err))
1004+
logger.Error(ctx, "devcontainer creation failed", slog.Error(err))
10001005
}
10011006

10021007
api.mu.Lock()
@@ -1009,7 +1014,7 @@ func (api *API) recreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, con
10091014
return xerrors.Errorf("start devcontainer: %w", err)
10101015
}
10111016

1012-
logger.Info(ctx, "devcontainer recreated successfully")
1017+
logger.Info(ctx, "devcontainer created successfully")
10131018

10141019
api.mu.Lock()
10151020
dc = api.knownDevcontainers[dc.WorkspaceFolder]
@@ -1032,7 +1037,7 @@ func (api *API) recreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, con
10321037
// Ensure an immediate refresh to accurately reflect the
10331038
// devcontainer state after recreation.
10341039
if err := api.RefreshContainers(ctx); err != nil {
1035-
logger.Error(ctx, "failed to trigger immediate refresh after devcontainer recreation", slog.Error(err))
1040+
logger.Error(ctx, "failed to trigger immediate refresh after devcontainer creation", slog.Error(err))
10361041
return xerrors.Errorf("refresh containers: %w", err)
10371042
}
10381043

0 commit comments

Comments
 (0)