Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
22b9be8
feat: add user maintenance schedule for max_ttl autostop
deansheather Jun 20, 2023
92c05b3
fixup! feat: add user maintenance schedule for max_ttl autostop
deansheather Jun 20, 2023
54d939a
fixup! feat: add user maintenance schedule for max_ttl autostop
deansheather Jun 21, 2023
b274c67
rename maintenance schedule to quiet hours schedule
deansheather Jun 28, 2023
5bf53eb
Merge branch 'main' into dean/user-maintenance-window
deansheather Jun 28, 2023
ede278e
stuff
deansheather Jun 28, 2023
06272e2
progress
deansheather Jun 28, 2023
a1ebbdb
progress
deansheather Jul 6, 2023
780812c
working
deansheather Jul 6, 2023
00e4a0f
tests mostly fixed
deansheather Jul 7, 2023
6cfd270
working!
deansheather Jul 7, 2023
53f5d62
move autostop algorithm to schedule package
deansheather Jul 10, 2023
eb1c1f6
more tests
deansheather Jul 10, 2023
3dbd077
Merge branch 'main' into dean/user-maintenance-window
deansheather Jul 10, 2023
0e9437e
Merge branch 'main' into dean/user-maintenance-window
deansheather Jul 12, 2023
fd26e69
add back max_ttl and put restart_requirement behind feature flag
deansheather Jul 12, 2023
cb9428e
fixup! add back max_ttl and put restart_requirement behind feature flag
deansheather Jul 12, 2023
024233a
fixup! add back max_ttl and put restart_requirement behind feature flag
deansheather Jul 12, 2023
c7ef9cb
fixup! add back max_ttl and put restart_requirement behind feature flag
deansheather Jul 12, 2023
4c70ade
fixup! add back max_ttl and put restart_requirement behind feature flag
deansheather Jul 13, 2023
2fb3053
Merge branch 'main' into dean/user-maintenance-window
deansheather Jul 13, 2023
554e837
Disable quiet hours endpoint if not entitled
deansheather Jul 13, 2023
eb46ae2
add DST and week calculation tests
deansheather Jul 13, 2023
6af3e33
fixup! add DST and week calculation tests
deansheather Jul 13, 2023
159d107
Merge branch 'main' into dean/user-maintenance-window
deansheather Jul 16, 2023
96f5e2e
rename interface methods, merge migrations
deansheather Jul 16, 2023
cd77138
steven comments and test fix
deansheather Jul 16, 2023
87b065b
fixup! steven comments and test fix
deansheather Jul 17, 2023
8658112
remove duration
deansheather Jul 19, 2023
fe26e3f
Merge branch 'main' into dean/user-maintenance-window
deansheather Jul 19, 2023
8cebc67
Merge branch 'main' into dean/user-maintenance-window
deansheather Jul 20, 2023
85142a6
fixup! Merge branch 'main' into dean/user-maintenance-window
deansheather Jul 20, 2023
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
Next Next commit
steven comments and test fix
  • Loading branch information
deansheather committed Jul 16, 2023
commit cd7713871b98fd8e0b9b4898181b355c8fd425c9
19 changes: 12 additions & 7 deletions cli/templateedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"fmt"
"net/http"
"strings"
"time"

"golang.org/x/xerrors"
Expand Down Expand Up @@ -90,12 +91,6 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
restartRequirementDaysOfWeek = []string{}
}

// Check that the user didn't specify a value that is not allowed.
_, err = codersdk.WeekdaysToBitmap(restartRequirementDaysOfWeek)
if err != nil {
return xerrors.Errorf("invalid restart requirement days of week: %w", err)
}

// NOTE: coderd will ignore empty fields.
req := codersdk.UpdateTemplateMeta{
Name: name,
Expand Down Expand Up @@ -160,7 +155,17 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
Description: "Edit the template restart requirement weekdays - workspaces created from this template must be restarted on the given weekdays. To unset this value for the template (and disable the restart requirement for the template), pass 'none'.",
// TODO(@dean): unhide when we delete max_ttl
Hidden: true,
Value: clibase.StringArrayOf(&restartRequirementDaysOfWeek),
Value: clibase.Validate(clibase.StringArrayOf(&restartRequirementDaysOfWeek), func(value *clibase.StringArray) error {
v := value.GetSlice()
if len(v) == 1 && v[0] == "none" {
return nil
}
_, err := codersdk.WeekdaysToBitmap(v)
if err != nil {
return xerrors.Errorf("invalid restart requirement days of week %q: %w", strings.Join(v, ","), err)
}
return nil
}),
},
{
Flag: "restart-requirement-weeks",
Expand Down
15 changes: 15 additions & 0 deletions coderd/schedule/autostop.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@ const (
// restartRequirementLeeway is the duration of time before a restart
// requirement where we skip the requirement and fall back to the next
// scheduled restart. This avoids workspaces being restarted too soon.
//
// E.g. If the workspace is started within an hour of the quiet hours, we
// will skip the restart requirement and use the next scheduled restart
// requirement.
restartRequirementLeeway = 1 * time.Hour

// restartRequirementBuffer is the duration of time we subtract from the
// time when calculating the next scheduled restart time. This avoids issues
// where autostart happens on the hour and the scheduled quiet hours are
// also on the hour.
//
// E.g. If the workspace is started at 12am (perhaps due to scheduled
// autostart) and the quiet hours is also 12am, the workspace will skip
// the day it's supposed to stop and use the next day instead. This is
// because getting the next cron schedule time will never include the
// time fed to the calculation (i.e. it's not inclusive). This happens
// because we always check for the next cron time by rounding down to
// midnight.
//
// This resolves that problem by subtracting 15 minutes from midnight
// when we check the next cron time.
restartRequirementBuffer = -15 * time.Minute
)

Expand Down
12 changes: 11 additions & 1 deletion coderd/schedule/autostop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,21 @@ func TestFindWeek(t *testing.T) {
currentWeek, err := schedule.WeeksSinceEpoch(now)
require.NoError(t, err)

currentWeekMondayExpected := now.AddDate(0, 0, -int(now.Weekday())+1)
diffMonday := now.Weekday() - time.Monday
if now.Weekday() == time.Sunday {
// Sunday is 0, but Monday is the first day of the week in the
// code.
diffMonday = 6
}
currentWeekMondayExpected := now.AddDate(0, 0, -int(diffMonday))
require.Equal(t, time.Monday, currentWeekMondayExpected.Weekday())
y, m, d := currentWeekMondayExpected.Date()
// Change to midnight.
currentWeekMondayExpected = time.Date(y, m, d, 0, 0, 0, 0, loc)

currentWeekMonday, err := schedule.GetMondayOfWeek(now.Location(), currentWeek)
require.NoError(t, err)
require.Equal(t, time.Monday, currentWeekMonday.Weekday())
require.Equal(t, currentWeekMondayExpected, currentWeekMonday)

t.Log("now", now)
Expand Down