Skip to content

fix: allow users to extend their running workspace's deadline #15895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
chore: re-add 'override-stop' as alias
  • Loading branch information
DanielleMaywood committed Dec 18, 2024
commit 88e3e5ff04af6eb64adba646b0047cda8e2ec306
5 changes: 3 additions & 2 deletions cli/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ func (r *RootCmd) scheduleStop() *serpent.Command {
func (r *RootCmd) scheduleExtend() *serpent.Command {
client := new(codersdk.Client)
extendCmd := &serpent.Command{
Use: "extend <workspace-name> <duration from now>",
Short: "Extend the stop time of a currently running workspace instance.",
Use: "extend <workspace-name> <duration from now>",
Aliases: []string{"override-stop"},
Short: "Extend the stop time of a currently running workspace instance.",
Long: scheduleExtendDescriptionLong + "\n" + FormatExamples(
Example{
Command: "coder schedule extend my-workspace 90m",
Expand Down
70 changes: 42 additions & 28 deletions cli/schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,32 +332,46 @@ func TestScheduleModify(t *testing.T) {

//nolint:paralleltest // t.Setenv
func TestScheduleOverride(t *testing.T) {
// Given
// Set timezone to Asia/Kolkata to surface any timezone-related bugs.
t.Setenv("TZ", "Asia/Kolkata")
loc, err := tz.TimezoneIANA()
require.NoError(t, err)
require.Equal(t, "Asia/Kolkata", loc.String())
sched, err := cron.Weekly("CRON_TZ=Europe/Dublin 30 7 * * Mon-Fri")
require.NoError(t, err, "invalid schedule")
ownerClient, _, _, ws := setupTestSchedule(t, sched)
now := time.Now()
// To avoid the likelihood of time-related flakes, only matching up to the hour.
expectedDeadline := time.Now().In(loc).Add(10 * time.Hour).Format("2006-01-02T15:")

// When: we override the stop schedule
inv, root := clitest.New(t,
"schedule", "extend", ws[0].OwnerName+"/"+ws[0].Name, "10h",
)

clitest.SetupConfig(t, ownerClient, root)
pty := ptytest.New(t).Attach(inv)
require.NoError(t, inv.Run())

// Then: the updated schedule should be shown
pty.ExpectMatch(ws[0].OwnerName + "/" + ws[0].Name)
pty.ExpectMatch(sched.Humanize())
pty.ExpectMatch(sched.Next(now).In(loc).Format(time.RFC3339))
pty.ExpectMatch("8h")
pty.ExpectMatch(expectedDeadline)
tests := []struct {
command string
}{
{command: "extend"},
// test for backwards compatibility
{command: "override-stop"},
}

for _, tt := range tests {
tt := tt

t.Run(tt.command, func(t *testing.T) {
// Given
// Set timezone to Asia/Kolkata to surface any timezone-related bugs.
t.Setenv("TZ", "Asia/Kolkata")
loc, err := tz.TimezoneIANA()
require.NoError(t, err)
require.Equal(t, "Asia/Kolkata", loc.String())
sched, err := cron.Weekly("CRON_TZ=Europe/Dublin 30 7 * * Mon-Fri")
require.NoError(t, err, "invalid schedule")
ownerClient, _, _, ws := setupTestSchedule(t, sched)
now := time.Now()
// To avoid the likelihood of time-related flakes, only matching up to the hour.
expectedDeadline := time.Now().In(loc).Add(10 * time.Hour).Format("2006-01-02T15:")

// When: we override the stop schedule
inv, root := clitest.New(t,
"schedule", tt.command, ws[0].OwnerName+"/"+ws[0].Name, "10h",
)

clitest.SetupConfig(t, ownerClient, root)
pty := ptytest.New(t).Attach(inv)
require.NoError(t, inv.Run())

// Then: the updated schedule should be shown
pty.ExpectMatch(ws[0].OwnerName + "/" + ws[0].Name)
pty.ExpectMatch(sched.Humanize())
pty.ExpectMatch(sched.Next(now).In(loc).Format(time.RFC3339))
pty.ExpectMatch("8h")
pty.ExpectMatch(expectedDeadline)
})
}
}
2 changes: 2 additions & 0 deletions cli/testdata/coder_schedule_extend_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ USAGE:

Extend the stop time of a currently running workspace instance.

Aliases: override-stop

* The new stop time is calculated from *now*.
* The new stop time must be at least 30 minutes in the future.
* The workspace template may restrict the maximum workspace runtime.
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/cli/schedule_extend.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading