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
working!
  • Loading branch information
deansheather committed Jul 7, 2023
commit 6cfd270d0dd1b89a7133154a7a31e67a4d8c1086
2 changes: 2 additions & 0 deletions coderd/database/dbfake/dbfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -4685,6 +4685,8 @@ func (q *fakeQuerier) UpdateTemplateScheduleByID(_ context.Context, arg database
tpl.AllowUserAutostop = arg.AllowUserAutostop
tpl.UpdatedAt = database.Now()
tpl.DefaultTTL = arg.DefaultTTL
tpl.RestartRequirementDaysOfWeek = arg.RestartRequirementDaysOfWeek
tpl.RestartRequirementWeeks = arg.RestartRequirementWeeks
tpl.FailureTTL = arg.FailureTTL
tpl.InactivityTTL = arg.InactivityTTL
q.templates[idx] = tpl
Expand Down
4 changes: 4 additions & 0 deletions coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,5 +768,9 @@ func (api *API) convertTemplate(
FailureTTLMillis: time.Duration(template.FailureTTL).Milliseconds(),
InactivityTTLMillis: time.Duration(template.InactivityTTL).Milliseconds(),
LockedTTLMillis: time.Duration(template.LockedTTL).Milliseconds(),
RestartRequirement: codersdk.TemplateRestartRequirement{
DaysOfWeek: codersdk.BitmapToWeekdays(uint8(template.RestartRequirementDaysOfWeek)),
Weeks: template.RestartRequirementWeeks,
},
}
}
2 changes: 1 addition & 1 deletion enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {

quietHoursStore, err := schedule.NewEnterpriseUserQuietHoursScheduleStore(api.DefaultQuietHoursSchedule, api.QuietHoursWindowDuration)
if err != nil {
api.Logger.Error(ctx, "unable to set up enterprise user quiet hours schedule store, quiet hours schedules will not be applied", slog.Error(err))
api.Logger.Error(ctx, "unable to set up enterprise user quiet hours schedule store, template restart requirements will not be applied to workspace builds", slog.Error(err))
} else {
api.AGPL.UserQuietHoursScheduleStore.Store(&quietHoursStore)
}
Expand Down
2 changes: 1 addition & 1 deletion enterprise/coderd/schedule/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (*EnterpriseTemplateScheduleStore) SetTemplateScheduleOptions(ctx context.C
return tpl, nil
}

err := agpl.VerifyTemplateRestartRequirement(uint8(opts.RestartRequirement.DaysOfWeek), opts.RestartRequirement.Weeks)
err := agpl.VerifyTemplateRestartRequirement(opts.RestartRequirement.DaysOfWeek, opts.RestartRequirement.Weeks)
if err != nil {
return database.Template{}, err
}
Expand Down
3 changes: 3 additions & 0 deletions enterprise/coderd/schedule/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func (s *enterpriseUserQuietHoursScheduleStore) parseSchedule(rawSchedule string
return agpl.UserQuietHoursScheduleOptions{}, xerrors.Errorf("parse daily schedule %q: %w", rawSchedule, err)
}
if strings.HasPrefix(sched.Time(), "cron(") {
// Times starting with "cron(" mean it isn't a single time and probably
// a range or a list of times as a cron expression. We only support
// single times for user quiet hours schedules.
// This shouldn't get hit during Gets, only Sets.
return agpl.UserQuietHoursScheduleOptions{}, xerrors.Errorf("daily schedule %q has more than one time: %v", rawSchedule, sched.Time())
}
Expand Down
7 changes: 4 additions & 3 deletions enterprise/coderd/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func TestTemplates(t *testing.T) {
require.Empty(t, 0, template.RestartRequirement.DaysOfWeek)
require.Zero(t, template.RestartRequirement.Weeks)

ctx := testutil.Context(t, testutil.WaitLong)
// ctx := testutil.Context(t, testutil.WaitLong)
ctx := context.Background()
updated, err := client.UpdateTemplateMeta(ctx, template.ID, codersdk.UpdateTemplateMeta{
Name: template.Name,
DisplayName: template.DisplayName,
Expand All @@ -61,12 +62,12 @@ func TestTemplates(t *testing.T) {
})
require.NoError(t, err)
require.Equal(t, []string{"monday", "saturday"}, updated.RestartRequirement.DaysOfWeek)
require.Equal(t, 3, updated.RestartRequirement.Weeks)
require.EqualValues(t, 3, updated.RestartRequirement.Weeks)

template, err = client.Template(ctx, template.ID)
require.NoError(t, err)
require.Equal(t, []string{"monday", "saturday"}, template.RestartRequirement.DaysOfWeek)
require.Equal(t, 3, template.RestartRequirement.Weeks)
require.EqualValues(t, 3, template.RestartRequirement.Weeks)
})
}

Expand Down