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

Commit04ba875

Browse files
committed
feat: add failed workspaces list to invalidate response
Add detailed error tracking to InvalidatePrebuildsResponse:- Invalidated: list of successfully invalidated workspace names- Failed: list of workspaces that failed with error messages- Count: number of successful invalidationsResponse structure:{ "count": 2, "invalidated": ["workspace-1", "workspace-2"], "failed": [ {"workspace_name": "workspace-3", "error": "error message"} ]}
1 parent4e6ad18 commit04ba875

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

‎coderd/templates.go‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,14 +1207,16 @@ func (api *API) postInvalidateTemplatePrebuilds(rw http.ResponseWriter, r *http.
12071207

12081208
iflen(prebuildWorkspaces)==0 {
12091209
httpapi.Write(ctx,rw,http.StatusOK, codersdk.InvalidatePrebuildsResponse{
1210-
Count:0,
1211-
Workspaces: []string{},
1210+
Count:0,
1211+
Invalidated: []string{},
1212+
Failed: []codersdk.InvalidatedPrebuildError{},
12121213
})
12131214
return
12141215
}
12151216

12161217
// Delete each prebuilt workspace using the existing workspace delete logic
12171218
varinvalidatedWorkspaces []string
1219+
varfailedWorkspaces []codersdk.InvalidatedPrebuildError
12181220

12191221
api.Logger.Info(ctx,"invalidating prebuilt workspaces",
12201222
slog.F("template_id",template.ID),
@@ -1245,6 +1247,10 @@ func (api *API) postInvalidateTemplatePrebuilds(rw http.ResponseWriter, r *http.
12451247
slog.F("workspace_name",workspace.Name),
12461248
slog.Error(err),
12471249
)
1250+
failedWorkspaces=append(failedWorkspaces, codersdk.InvalidatedPrebuildError{
1251+
WorkspaceName:workspace.Name,
1252+
Error:err.Error(),
1253+
})
12481254
continue
12491255
}
12501256

@@ -1254,11 +1260,12 @@ func (api *API) postInvalidateTemplatePrebuilds(rw http.ResponseWriter, r *http.
12541260
api.Logger.Info(ctx,"completed prebuild invalidation",
12551261
slog.F("template_id",template.ID),
12561262
slog.F("invalidated",len(invalidatedWorkspaces)),
1257-
slog.F("failed",len(prebuildWorkspaces)-len(invalidatedWorkspaces)),
1263+
slog.F("failed",len(failedWorkspaces)),
12581264
)
12591265

12601266
httpapi.Write(ctx,rw,http.StatusOK, codersdk.InvalidatePrebuildsResponse{
1261-
Count:len(invalidatedWorkspaces),
1262-
Workspaces:invalidatedWorkspaces,
1267+
Count:len(invalidatedWorkspaces),
1268+
Invalidated:invalidatedWorkspaces,
1269+
Failed:failedWorkspaces,
12631270
})
12641271
}

‎codersdk/templates.go‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,20 @@ func (c *Client) StarterTemplates(ctx context.Context) ([]TemplateExample, error
510510

511511
// InvalidatePrebuildsResponse contains the result of invalidating prebuilt workspaces.
512512
typeInvalidatePrebuildsResponsestruct {
513-
// Count is the number of prebuilt workspaces that were invalidated.
513+
// Count is the number of prebuilt workspaces that weresuccessfullyinvalidated.
514514
Countint`json:"count"`
515-
// Workspaces is the list of invalidated prebuilt workspace names.
516-
Workspaces []string`json:"workspaces"`
515+
// Invalidated is the list of successfully invalidated prebuilt workspace names.
516+
Invalidated []string`json:"invalidated"`
517+
// Failed is the list of prebuilt workspace names that failed to invalidate with error messages.
518+
Failed []InvalidatedPrebuildError`json:"failed,omitempty"`
519+
}
520+
521+
// InvalidatedPrebuildError represents a failed prebuild invalidation.
522+
typeInvalidatedPrebuildErrorstruct {
523+
// WorkspaceName is the name of the workspace that failed to invalidate.
524+
WorkspaceNamestring`json:"workspace_name"`
525+
// Error is the error message.
526+
Errorstring`json:"error"`
517527
}
518528

519529
// InvalidateTemplatePrebuilds invalidates all prebuilt workspaces for the

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp