Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcf17cd4

Browse files
committed
fix review comments
1 parentfb4cdad commitcf17cd4

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

‎agent/agentcontainers/api.go

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func (api *API) updaterLoop() {
296296
iferr:=api.cleanupSubAgents(api.ctx);err!=nil {
297297
api.logger.Error(api.ctx,"cleanup subagents failed",slog.Error(err))
298298
}else {
299-
api.logger.Debug(api.ctx,"subagentcleanup complete")
299+
api.logger.Debug(api.ctx,"cleanup subagents complete")
300300
}
301301

302302
// Perform an initial update to populate the container list, this
@@ -440,6 +440,20 @@ func (api *API) updateContainers(ctx context.Context) error {
440440
// on the latest list of containers. This method assumes that api.mu is
441441
// held.
442442
func (api*API)processUpdatedContainersLocked(ctx context.Context,updated codersdk.WorkspaceAgentListContainersResponse) {
443+
dcFields:=func(dc codersdk.WorkspaceAgentDevcontainer) []slog.Field {
444+
f:= []slog.Field{
445+
slog.F("devcontainer_id",dc.ID),
446+
slog.F("devcontainer_name",dc.Name),
447+
slog.F("workspace_folder",dc.WorkspaceFolder),
448+
slog.F("config_path",dc.ConfigPath),
449+
}
450+
ifdc.Container!=nil {
451+
f=append(f,slog.F("container_id",dc.Container.ID))
452+
f=append(f,slog.F("container_name",dc.Container.FriendlyName))
453+
}
454+
returnf
455+
}
456+
443457
// Reset the container links in known devcontainers to detect if
444458
// they still exist.
445459
for_,dc:=rangeapi.knownDevcontainers {
@@ -460,6 +474,13 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
460474
continue
461475
}
462476

477+
logger:=api.logger.With(
478+
slog.F("container_id",updated.Containers[i].ID),
479+
slog.F("container_name",updated.Containers[i].FriendlyName),
480+
slog.F("workspace_folder",workspaceFolder),
481+
slog.F("config_file",configFile),
482+
)
483+
463484
ifdc,ok:=api.knownDevcontainers[workspaceFolder];ok {
464485
// If no config path is set, this devcontainer was defined
465486
// in Terraform without the optional config file. Assume the
@@ -468,7 +489,7 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
468489
ifdc.ConfigPath==""&&configFile!="" {
469490
dc.ConfigPath=configFile
470491
iferr:=api.watcher.Add(configFile);err!=nil {
471-
api.logger.Error(ctx,"watch devcontainer config file failed",slog.Error(err),slog.F("file",configFile))
492+
logger.With(dcFields(dc)...).Error(ctx,"watch devcontainer config file failed",slog.Error(err))
472493
}
473494
}
474495

@@ -477,13 +498,7 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
477498
continue
478499
}
479500

480-
ifconfigFile!="" {
481-
iferr:=api.watcher.Add(configFile);err!=nil {
482-
api.logger.Error(ctx,"watch devcontainer config file failed",slog.Error(err),slog.F("file",configFile))
483-
}
484-
}
485-
486-
api.knownDevcontainers[workspaceFolder]= codersdk.WorkspaceAgentDevcontainer{
501+
dc:= codersdk.WorkspaceAgentDevcontainer{
487502
ID:uuid.New(),
488503
Name:"",// Updated later based on container state.
489504
WorkspaceFolder:workspaceFolder,
@@ -492,11 +507,21 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
492507
Dirty:false,// Updated later based on config file changes.
493508
Container:container,
494509
}
510+
511+
ifconfigFile!="" {
512+
iferr:=api.watcher.Add(configFile);err!=nil {
513+
logger.With(dcFields(dc)...).Error(ctx,"watch devcontainer config file failed",slog.Error(err))
514+
}
515+
}
516+
517+
api.knownDevcontainers[workspaceFolder]=dc
495518
}
496519

497520
// Iterate through all known devcontainers and update their status
498521
// based on the current state of the containers.
499522
for_,dc:=rangeapi.knownDevcontainers {
523+
logger:=api.logger.With(dcFields(dc)...)
524+
500525
ifdc.Container!=nil {
501526
if!api.devcontainerNames[dc.Name] {
502527
// If the devcontainer name wasn't set via terraform, we
@@ -532,7 +557,7 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
532557
if_,injected:=api.injectedSubAgentProcs[dc.Container.ID];!injected&&dc.Status==codersdk.WorkspaceAgentDevcontainerStatusRunning {
533558
err:=api.injectSubAgentIntoContainerLocked(ctx,dc)
534559
iferr!=nil {
535-
api.logger.Error(ctx,"inject subagent into container failed",slog.Error(err))
560+
logger.Error(ctx,"inject subagent into container failed",slog.Error(err))
536561
}
537562
}
538563

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp