feat: plumb time_til_autostop_notify template field (#26439)

This commit is contained in:
Jon Ayers
2026-06-23 17:32:47 -05:00
committed by GitHub
parent a11f349c16
commit 4cfed1b3ed
23 changed files with 403 additions and 32 deletions
+17 -6
View File
@@ -23,6 +23,7 @@ func (r *RootCmd) templateEdit() *serpent.Command {
icon string
defaultTTL time.Duration
activityBump time.Duration
timeTilAutostopNotify time.Duration
autostopRequirementDaysOfWeek []string
autostopRequirementWeeks int64
autostartRequirementDaysOfWeek []string
@@ -113,6 +114,10 @@ func (r *RootCmd) templateEdit() *serpent.Command {
activityBump = time.Duration(template.ActivityBumpMillis) * time.Millisecond
}
if !userSetOption(inv, "autostop-reminder") {
timeTilAutostopNotify = time.Duration(template.TimeTilAutostopNotifyMillis) * time.Millisecond
}
if !userSetOption(inv, "allow-user-autostop") {
allowUserAutostop = template.AllowUserAutostop
}
@@ -174,12 +179,13 @@ func (r *RootCmd) templateEdit() *serpent.Command {
}
req := codersdk.UpdateTemplateMeta{
Name: &name,
DisplayName: &displayName,
Description: &description,
Icon: &icon,
DefaultTTLMillis: ptr.Ref(defaultTTL.Milliseconds()),
ActivityBumpMillis: ptr.Ref(activityBump.Milliseconds()),
Name: &name,
DisplayName: &displayName,
Description: &description,
Icon: &icon,
DefaultTTLMillis: ptr.Ref(defaultTTL.Milliseconds()),
ActivityBumpMillis: ptr.Ref(activityBump.Milliseconds()),
TimeTilAutostopNotifyMillis: ptr.Ref(timeTilAutostopNotify.Milliseconds()),
AutostopRequirement: &codersdk.TemplateAutostopRequirement{
DaysOfWeek: autostopRequirementDaysOfWeek,
Weeks: autostopRequirementWeeks,
@@ -248,6 +254,11 @@ func (r *RootCmd) templateEdit() *serpent.Command {
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.",
Value: serpent.DurationOf(&activityBump),
},
{
Flag: "autostop-reminder",
Description: "Edit how long before the autostop deadline a reminder notification is sent for workspaces created from this template, in Go duration format (e.g. 1h, 30m). Set to 0 to disable.",
Value: serpent.DurationOf(&timeTilAutostopNotify),
},
{
Flag: "autostart-requirement-weekdays",
Description: "Edit the template autostart requirement weekdays - workspaces created from this template can only autostart on the given weekdays. To unset this value for the template (and allow autostart on all days), pass 'all'.",
+3
View File
@@ -44,6 +44,7 @@ func TestTemplateEdit(t *testing.T) {
desc := "lorem ipsum dolor sit amet et cetera"
icon := "/icon/new-icon.png"
defaultTTL := 12 * time.Hour
timeTilAutostopNotify := 5 * time.Minute
allowUserCancelWorkspaceJobs := false
cmdArgs := []string{
@@ -55,6 +56,7 @@ func TestTemplateEdit(t *testing.T) {
"--description", desc,
"--icon", icon,
"--default-ttl", defaultTTL.String(),
"--autostop-reminder", timeTilAutostopNotify.String(),
"--allow-user-cancel-workspace-jobs=" + strconv.FormatBool(allowUserCancelWorkspaceJobs),
}
inv, root := clitest.New(t, cmdArgs...)
@@ -73,6 +75,7 @@ func TestTemplateEdit(t *testing.T) {
assert.Equal(t, desc, updated.Description)
assert.Equal(t, icon, updated.Icon)
assert.Equal(t, defaultTTL.Milliseconds(), updated.DefaultTTLMillis)
assert.Equal(t, timeTilAutostopNotify.Milliseconds(), updated.TimeTilAutostopNotifyMillis)
assert.Equal(t, allowUserCancelWorkspaceJobs, updated.AllowUserCancelWorkspaceJobs)
})
t.Run("FirstEmptyThenNotModified", func(t *testing.T) {
+5
View File
@@ -31,6 +31,11 @@ OPTIONS:
this value for the template (and allow autostart on all days), pass
'all'.
--autostop-reminder duration
Edit how long before the autostop deadline a reminder notification is
sent for workspaces created from this template, in Go duration format
(e.g. 1h, 30m). Set to 0 to disable.
--autostop-requirement-weekdays [monday|tuesday|wednesday|thursday|friday|saturday|sunday|none]
Edit the template autostop requirement weekdays - workspaces created
from this template must be restarted on the given weekdays. To unset