mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add prebuild invalidation via last_invalidated_at timestamp (#20582)
Updates #17917
This commit is contained in:
@@ -513,3 +513,34 @@ func (c *Client) StarterTemplates(ctx context.Context) ([]TemplateExample, error
|
||||
var templateExamples []TemplateExample
|
||||
return templateExamples, json.NewDecoder(res.Body).Decode(&templateExamples)
|
||||
}
|
||||
|
||||
type InvalidatePresetsResponse struct {
|
||||
Invalidated []InvalidatedPreset `json:"invalidated"`
|
||||
}
|
||||
|
||||
type InvalidatedPreset struct {
|
||||
TemplateName string `json:"template_name"`
|
||||
TemplateVersionName string `json:"template_version_name"`
|
||||
PresetName string `json:"preset_name"`
|
||||
}
|
||||
|
||||
// InvalidateTemplatePresets invalidates all presets for the
|
||||
// template's active version by setting last_invalidated_at timestamp.
|
||||
// The reconciler will then mark these prebuilds as expired and create new ones.
|
||||
func (c *Client) InvalidateTemplatePresets(ctx context.Context, template uuid.UUID) (InvalidatePresetsResponse, error) {
|
||||
res, err := c.Request(ctx, http.MethodPost,
|
||||
fmt.Sprintf("/api/v2/templates/%s/prebuilds/invalidate", template),
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return InvalidatePresetsResponse{}, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return InvalidatePresetsResponse{}, ReadBodyAsError(res)
|
||||
}
|
||||
|
||||
var response InvalidatePresetsResponse
|
||||
return response, json.NewDecoder(res.Body).Decode(&response)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user