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

Commite1e352d

Browse files
authored
feat: add template activity_bump property (#11734)
Allows template admins to configure the activity bump duration. Defaults to 1h.
1 parentfead57f commite1e352d

File tree

34 files changed

+354
-90
lines changed

34 files changed

+354
-90
lines changed

‎cli/templateedit.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
2323
descriptionstring
2424
iconstring
2525
defaultTTL time.Duration
26+
activityBump time.Duration
2627
maxTTL time.Duration
2728
autostopRequirementDaysOfWeek []string
2829
autostopRequirementWeeksint64
@@ -108,6 +109,10 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
108109
defaultTTL=time.Duration(template.DefaultTTLMillis)*time.Millisecond
109110
}
110111

112+
if!userSetOption(inv,"activity-bump") {
113+
activityBump=time.Duration(template.ActivityBumpMillis)*time.Millisecond
114+
}
115+
111116
if!userSetOption(inv,"allow-user-autostop") {
112117
allowUserAutostop=template.AllowUserAutostop
113118
}
@@ -168,12 +173,13 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
168173
}
169174

170175
req:= codersdk.UpdateTemplateMeta{
171-
Name:name,
172-
DisplayName:displayName,
173-
Description:description,
174-
Icon:icon,
175-
DefaultTTLMillis:defaultTTL.Milliseconds(),
176-
MaxTTLMillis:maxTTL.Milliseconds(),
176+
Name:name,
177+
DisplayName:displayName,
178+
Description:description,
179+
Icon:icon,
180+
DefaultTTLMillis:defaultTTL.Milliseconds(),
181+
ActivityBumpMillis:activityBump.Milliseconds(),
182+
MaxTTLMillis:maxTTL.Milliseconds(),
177183
AutostopRequirement:&codersdk.TemplateAutostopRequirement{
178184
DaysOfWeek:autostopRequirementDaysOfWeek,
179185
Weeks:autostopRequirementWeeks,
@@ -233,6 +239,11 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
233239
Description:"Edit the template default time before shutdown - workspaces created from this template default to this value. Maps to\"Default autostop\" in the UI.",
234240
Value:clibase.DurationOf(&defaultTTL),
235241
},
242+
{
243+
Flag:"activity-bump",
244+
Description:"Edit the template activity bump - workspaces created from this template will have their shutdown time bumped by this value when activity is detected. Maps to\"Activity bump\" in the UI.",
245+
Value:clibase.DurationOf(&activityBump),
246+
},
236247
{
237248
Flag:"max-ttl",
238249
Description:"Edit the template maximum time before shutdown - workspaces created from this template must shutdown within the given duration after starting, regardless of user activity. This is an enterprise-only feature. Maps to\"Max lifetime\" in the UI.",

‎cli/templateedit_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func TestTemplateEdit(t *testing.T) {
9393
"--description",template.Description,
9494
"--icon",template.Icon,
9595
"--default-ttl", (time.Duration(template.DefaultTTLMillis)*time.Millisecond).String(),
96+
"--activity-bump", (time.Duration(template.ActivityBumpMillis)*time.Millisecond).String(),
9697
"--allow-user-cancel-workspace-jobs="+strconv.FormatBool(template.AllowUserCancelWorkspaceJobs),
9798
}
9899
inv,root:=clitest.New(t,cmdArgs...)

‎cli/testdata/coder_templates_edit_--help.golden

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ USAGE:
66
Edit the metadata of a template by name.
77

88
OPTIONS:
9+
--activity-bump duration
10+
Edit the template activity bump - workspaces created from this
11+
template will have their shutdown time bumped by this value when
12+
activity is detected. Maps to "Activity bump" in the UI.
13+
914
--allow-user-autostart bool (default: true)
1015
Allow users to configure autostart for workspaces on this template.
1116
This can only be disabled in enterprise.

‎coderd/agentapi/activitybump_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
4141
maxDeadlineOffset*time.Duration
4242
workspaceTTL time.Duration
4343
templateTTL time.Duration
44+
templateActivityBump time.Duration
4445
templateDisallowsUserAutostopbool
4546
expectedBump time.Duration
4647
// If the tests get queued, we need to be able to set the next autostart
@@ -137,6 +138,26 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
137138
expectedBump:10*time.Hour+ (time.Minute*30),
138139
nextAutostart:func(now time.Time) time.Time {returnnow.Add(time.Minute*30) },
139140
},
141+
{
142+
// Custom activity bump duration specified on the template.
143+
name:"TemplateCustomActivityBump",
144+
transition:database.WorkspaceTransitionStart,
145+
jobCompletedAt: sql.NullTime{Valid:true,Time:dbtime.Now().Add(-30*time.Minute)},
146+
buildDeadlineOffset:ptr.Ref(-30*time.Minute),
147+
workspaceTTL:8*time.Hour,
148+
templateActivityBump:5*time.Hour,// instead of default 1h
149+
expectedBump:5*time.Hour,
150+
},
151+
{
152+
// Activity bump duration is 0.
153+
name:"TemplateCustomActivityBumpZero",
154+
transition:database.WorkspaceTransitionStart,
155+
jobCompletedAt: sql.NullTime{Valid:true,Time:dbtime.Now().Add(-30*time.Minute)},
156+
buildDeadlineOffset:ptr.Ref(-30*time.Minute),
157+
workspaceTTL:8*time.Hour,
158+
templateActivityBump:-1,// negative values get changed to 0 in the test
159+
expectedBump:0,
160+
},
140161
} {
141162
tt:=tt
142163
for_,tz:=rangetimezones {
@@ -186,11 +207,19 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
186207
buildID=uuid.New()
187208
)
188209

210+
activityBump:=1*time.Hour
211+
iftt.templateActivityBump<0 {
212+
// less than 0 => 0
213+
activityBump=0
214+
}elseiftt.templateActivityBump!=0 {
215+
activityBump=tt.templateActivityBump
216+
}
189217
require.NoError(t,db.UpdateTemplateScheduleByID(ctx, database.UpdateTemplateScheduleByIDParams{
190218
ID:template.ID,
191219
UpdatedAt:dbtime.Now(),
192220
AllowUserAutostop:!tt.templateDisallowsUserAutostop,
193221
DefaultTTL:int64(tt.templateTTL),
222+
ActivityBump:int64(activityBump),
194223
}),"unexpected error updating template schedule")
195224

196225
varbuildNumberint32=1

‎coderd/apidoc/docs.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dbmem/dbmem.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,10 +841,14 @@ func (q *FakeQuerier) ActivityBumpWorkspace(ctx context.Context, arg database.Ac
841841
iferr!=nil {
842842
returnerr
843843
}
844+
iftemplate.ActivityBump==0 {
845+
returnnil
846+
}
847+
activityBump:=time.Duration(template.ActivityBump)
844848

845849
varttlDur time.Duration
846-
ifnow.Add(time.Hour).After(arg.NextAutostart)&&arg.NextAutostart.After(now) {
847-
// Extend to TTL
850+
ifnow.Add(activityBump).After(arg.NextAutostart)&&arg.NextAutostart.After(now) {
851+
// Extend to TTL (NOT activity bump)
848852
add:=arg.NextAutostart.Sub(now)
849853
ifworkspace.Ttl.Valid&&template.AllowUserAutostop {
850854
add+=time.Duration(workspace.Ttl.Int64)
@@ -853,7 +857,8 @@ func (q *FakeQuerier) ActivityBumpWorkspace(ctx context.Context, arg database.Ac
853857
}
854858
ttlDur=add
855859
}else {
856-
ttlDur=time.Hour
860+
// Otherwise, default to regular activity bump duration.
861+
ttlDur=activityBump
857862
}
858863

859864
// Only bump if 5% of the deadline has passed.
@@ -6543,6 +6548,7 @@ func (q *FakeQuerier) UpdateTemplateScheduleByID(_ context.Context, arg database
65436548
tpl.AllowUserAutostop=arg.AllowUserAutostop
65446549
tpl.UpdatedAt=dbtime.Now()
65456550
tpl.DefaultTTL=arg.DefaultTTL
6551+
tpl.ActivityBump=arg.ActivityBump
65466552
tpl.UseMaxTtl=arg.UseMaxTtl
65476553
tpl.MaxTTL=arg.MaxTTL
65486554
tpl.AutostopRequirementDaysOfWeek=arg.AutostopRequirementDaysOfWeek

‎coderd/database/dump.sql

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
DROPVIEW template_with_users;
2+
3+
ALTERTABLE templates DROP COLUMN activity_bump;
4+
5+
CREATE VIEW
6+
template_with_users
7+
AS
8+
SELECT
9+
templates.*,
10+
coalesce(visible_users.avatar_url,'')AS created_by_avatar_url,
11+
coalesce(visible_users.username,'')AS created_by_username
12+
FROM
13+
templates
14+
LEFT JOIN
15+
visible_users
16+
ON
17+
templates.created_by=visible_users.id;
18+
19+
COMMENT ON VIEW template_with_users IS'Joins in the username + avatar url of the created by user.';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ALTERTABLE templates ADD COLUMN activity_bumpbigint DEFAULT'3600000000000'::bigintNOT NULL;-- 1 hour
2+
3+
DROPVIEW template_with_users;
4+
5+
CREATE VIEW
6+
template_with_users
7+
AS
8+
SELECT
9+
templates.*,
10+
coalesce(visible_users.avatar_url,'')AS created_by_avatar_url,
11+
coalesce(visible_users.username,'')AS created_by_username
12+
FROM
13+
templates
14+
LEFT JOIN
15+
visible_users
16+
ON
17+
templates.created_by=visible_users.id;
18+
19+
COMMENT ON VIEW template_with_users IS'Joins in the username + avatar url of the created by user.';

‎coderd/database/modelqueries.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate
9090
&i.RequireActiveVersion,
9191
&i.Deprecated,
9292
&i.UseMaxTtl,
93+
&i.ActivityBump,
9394
&i.CreatedByAvatarURL,
9495
&i.CreatedByUsername,
9596
);err!=nil {

‎coderd/database/models.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/querier.go

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp