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

Commitde8149f

Browse files
authored
chore: move template meta last_used_at update to workspacestats (#13415)
1 parent19530c6 commitde8149f

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

‎coderd/schedule/template.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,38 +114,38 @@ func VerifyTemplateAutostartRequirement(days uint8) error {
114114
}
115115

116116
typeTemplateScheduleOptionsstruct {
117-
UserAutostartEnabledbool`json:"user_autostart_enabled"`
118-
UserAutostopEnabledbool`json:"user_autostop_enabled"`
119-
DefaultTTL time.Duration`json:"default_ttl"`
117+
UserAutostartEnabledbool
118+
UserAutostopEnabledbool
119+
DefaultTTL time.Duration
120120
// ActivityBump dictates the duration to bump the workspace's deadline by if
121121
// Coder detects activity from the user. A value of 0 means no bumping.
122-
ActivityBump time.Duration`json:"activity_bump"`
122+
ActivityBump time.Duration
123123
// AutostopRequirement dictates when the workspace must be restarted. This
124124
// used to be handled by MaxTTL.
125-
AutostopRequirementTemplateAutostopRequirement`json:"autostop_requirement"`
125+
AutostopRequirementTemplateAutostopRequirement
126126
// AutostartRequirement dictates when the workspace can be auto started.
127-
AutostartRequirementTemplateAutostartRequirement`json:"autostart_requirement"`
127+
AutostartRequirementTemplateAutostartRequirement
128128
// FailureTTL dictates the duration after which failed workspaces will be
129129
// stopped automatically.
130-
FailureTTL time.Duration`json:"failure_ttl"`
130+
FailureTTL time.Duration
131131
// TimeTilDormant dictates the duration after which inactive workspaces will
132132
// go dormant.
133-
TimeTilDormant time.Duration`json:"time_til_dormant"`
133+
TimeTilDormant time.Duration
134134
// TimeTilDormantAutoDelete dictates the duration after which dormant workspaces will be
135135
// permanently deleted.
136-
TimeTilDormantAutoDelete time.Duration`json:"time_til_dormant_autodelete"`
136+
TimeTilDormantAutoDelete time.Duration
137137
// UpdateWorkspaceLastUsedAt updates the template's workspaces'
138138
// last_used_at field. This is useful for preventing updates to the
139139
// templates inactivity_ttl immediately triggering a dormant action against
140140
// workspaces whose last_used_at field violates the new template
141141
// inactivity_ttl threshold.
142-
UpdateWorkspaceLastUsedAtbool`json:"update_workspace_last_used_at"`
142+
UpdateWorkspaceLastUsedAtfunc(ctx context.Context,db database.Store,templateID uuid.UUID,lastUsedAt time.Time)error`json:"update_workspace_last_used_at"`
143143
// UpdateWorkspaceDormantAt updates the template's workspaces'
144144
// dormant_at field. This is useful for preventing updates to the
145145
// templates locked_ttl immediately triggering a delete action against
146146
// workspaces whose dormant_at field violates the new template time_til_dormant_autodelete
147147
// threshold.
148-
UpdateWorkspaceDormantAtbool`json:"update_workspace_dormant_at"`
148+
UpdateWorkspaceDormantAtbool
149149
}
150150

151151
// TemplateScheduleStore provides an interface for retrieving template

‎coderd/templates.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/coder/coder/v2/coderd/schedule"
2424
"github.com/coder/coder/v2/coderd/telemetry"
2525
"github.com/coder/coder/v2/coderd/util/ptr"
26+
"github.com/coder/coder/v2/coderd/workspacestats"
2627
"github.com/coder/coder/v2/codersdk"
2728
"github.com/coder/coder/v2/examples"
2829
)
@@ -726,6 +727,10 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
726727
failureTTL:=time.Duration(req.FailureTTLMillis)*time.Millisecond
727728
inactivityTTL:=time.Duration(req.TimeTilDormantMillis)*time.Millisecond
728729
timeTilDormantAutoDelete:=time.Duration(req.TimeTilDormantAutoDeleteMillis)*time.Millisecond
730+
varupdateWorkspaceLastUsedAt workspacestats.UpdateTemplateWorkspacesLastUsedAtFunc
731+
ifreq.UpdateWorkspaceLastUsedAt {
732+
updateWorkspaceLastUsedAt=workspacestats.UpdateTemplateWorkspacesLastUsedAt
733+
}
729734

730735
ifdefaultTTL!=time.Duration(template.DefaultTTL)||
731736
activityBump!=time.Duration(template.ActivityBump)||
@@ -755,7 +760,7 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
755760
FailureTTL:failureTTL,
756761
TimeTilDormant:inactivityTTL,
757762
TimeTilDormantAutoDelete:timeTilDormantAutoDelete,
758-
UpdateWorkspaceLastUsedAt:req.UpdateWorkspaceLastUsedAt,
763+
UpdateWorkspaceLastUsedAt:updateWorkspaceLastUsedAt,
759764
UpdateWorkspaceDormantAt:req.UpdateWorkspaceDormantAt,
760765
})
761766
iferr!=nil {

‎coderd/workspacestats/reporter.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,16 @@ func (r *Reporter) ReportAgentStats(ctx context.Context, now time.Time, workspac
192192

193193
returnnil
194194
}
195+
196+
typeUpdateTemplateWorkspacesLastUsedAtFuncfunc(ctx context.Context,db database.Store,templateID uuid.UUID,lastUsedAt time.Time)error
197+
198+
funcUpdateTemplateWorkspacesLastUsedAt(ctx context.Context,db database.Store,templateID uuid.UUID,lastUsedAt time.Time)error {
199+
err:=db.UpdateTemplateWorkspacesLastUsedAt(ctx, database.UpdateTemplateWorkspacesLastUsedAtParams{
200+
TemplateID:templateID,
201+
LastUsedAt:lastUsedAt,
202+
})
203+
iferr!=nil {
204+
returnxerrors.Errorf("update template workspaces last used at: %w",err)
205+
}
206+
returnnil
207+
}

‎enterprise/coderd/schedule/template.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,10 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
168168
returnxerrors.Errorf("update deleting_at of all workspaces for new time_til_dormant_autodelete %q: %w",opts.TimeTilDormantAutoDelete,err)
169169
}
170170

171-
ifopts.UpdateWorkspaceLastUsedAt {
172-
// nolint:gocritic // (#13146) Will be moved soon as part of refactor.
173-
err=tx.UpdateTemplateWorkspacesLastUsedAt(ctx, database.UpdateTemplateWorkspacesLastUsedAtParams{
174-
TemplateID:tpl.ID,
175-
LastUsedAt:dbtime.Now(),
176-
})
171+
ifopts.UpdateWorkspaceLastUsedAt!=nil {
172+
err=opts.UpdateWorkspaceLastUsedAt(ctx,tx,tpl.ID,s.now())
177173
iferr!=nil {
178-
returnxerrors.Errorf("updatetemplate workspaces last_used_at: %w",err)
174+
returnxerrors.Errorf("updateworkspace last used at: %w",err)
179175
}
180176
}
181177

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp