schedule
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Index¶
- Constants
- Variables
- func GetMondayOfWeek(loc *time.Location, n int64) (time.Time, error)
- func GetNextApplicableMondayOfNWeeks(now time.Time, n int64) (time.Time, error)
- func NextAllowedAutostart(at time.Time, wsSchedule string, templateSchedule TemplateScheduleOptions) (time.Time, error)
- func NextAutostart(at time.Time, wsSchedule string, templateSchedule TemplateScheduleOptions) (time.Time, bool)
- func TemplateAutostopRequirementEpoch(loc *time.Location) time.Time
- func VerifyTemplateAutostartRequirement(days uint8) error
- func VerifyTemplateAutostopRequirement(days uint8, weeks int64) error
- func WeeksSinceEpoch(now time.Time) (int64, error)
- type AutostopTime
- type CalculateAutostopParams
- type MockTemplateScheduleStore
- type MockUserQuietHoursScheduleStore
- type TemplateAutostartRequirement
- type TemplateAutostopRequirement
- type TemplateScheduleOptions
- type TemplateScheduleStore
- type UserQuietHoursScheduleOptions
- type UserQuietHoursScheduleStore
Constants¶
const MaxTemplateAutostopRequirementWeeks = 16
Variables¶
var DaysOfWeek = []time.Weekday{time.Monday,time.Tuesday,time.Wednesday,time.Thursday,time.Friday,time.Saturday,time.Sunday,}
DaysOfWeek intentionally starts on Monday as opposed to Sunday so the weekenddays are contiguous in the bitmap. This matters greatly when doing restartsevery second week or more to avoid workspaces restarting "at the start" ofthe week rather than "at the end" of the week.
var ErrNoAllowedAutostart =xerrors.New("no allowed autostart")
var ErrUserCannotSetQuietHoursSchedule =xerrors.New("user cannot set custom quiet hours schedule due to deployment configuration")
Functions¶
funcGetMondayOfWeek¶
GetMondayOfWeek gets the Monday (0:00) of the n-th week since epoch.
funcGetNextApplicableMondayOfNWeeks¶
GetNextApplicableMondayOfNWeeks gets the next Monday (0:00) of the next weekdivisible by n since epoch. If the next applicable week is invalid for anyreason, the week after will be used instead (up to 2 attempts).
If the current week is divisible by n, then the provided time is returned asis.
The timezone embedded in the time object is used to determine the epoch.
funcNextAllowedAutostart¶added inv2.19.0
funcNextAutostart¶added inv2.11.0
func NextAutostart(attime.Time, wsSchedulestring, templateScheduleTemplateScheduleOptions) (time.Time,bool)
NextAutostart takes the workspace and template schedule and returns the next autostart scheduleafter "at". The boolean returned is if the autostart should be allowed to start based on the templateschedule.
funcTemplateAutostopRequirementEpoch¶added inv2.1.5
funcVerifyTemplateAutostartRequirement¶added inv2.3.1
VerifyTemplateAutostartRequirement returns an error if the autostartrequirement is invalid.
funcVerifyTemplateAutostopRequirement¶added inv2.1.5
VerifyTemplateAutostopRequirement returns an error if the autostoprequirement is invalid.
Types¶
typeAutostopTime¶
type AutostopTime struct {// Deadline is the time when the workspace will be stopped. The value can be// bumped by user activity or manually by the user via the UI.Deadlinetime.Time// MaxDeadline is the maximum value for deadline.MaxDeadlinetime.Time}
funcCalculateAutostop¶
func CalculateAutostop(ctxcontext.Context, paramsCalculateAutostopParams) (AutostopTime,error)
CalculateAutostop calculates the deadline and max_deadline for a workspacebuild.
Deadline is the time when the workspace will be stopped, as long as itdoesn't see any new activity (such as SSH, app requests, etc.). When activityis detected the deadline is bumped by the workspace's TTL (this only happenswhen activity is detected and more than 20% of the TTL has passed to savedatabase queries).
MaxDeadline is the maximum value for deadline. The deadline cannot be bumpedpast this value, so it denotes the absolute deadline that the workspace buildmust be stopped by. MaxDeadline is calculated using the template's "autostoprequirement" settings and the user's "quiet hours" settings to pick a timeoutside of working hours.
Deadline is a cost saving measure, while max deadline is acompliance/updating measure.
typeCalculateAutostopParams¶
type CalculateAutostopParams struct {Databasedatabase.StoreTemplateScheduleStoreTemplateScheduleStoreUserQuietHoursScheduleStoreUserQuietHoursScheduleStore// WorkspaceAutostart can be the empty string if no workspace autostart// is configured.// If configured, this is expected to be a cron weekly event parsable// by autobuild.NextAutostartWorkspaceAutostartstringNowtime.TimeWorkspacedatabase.WorkspaceTable}
typeMockTemplateScheduleStore¶
type MockTemplateScheduleStore struct {GetFn func(ctxcontext.Context, dbdatabase.Store, templateIDuuid.UUID) (TemplateScheduleOptions,error)SetFn func(ctxcontext.Context, dbdatabase.Store, templatedatabase.Template, optionsTemplateScheduleOptions) (database.Template,error)}
typeMockUserQuietHoursScheduleStore¶
type MockUserQuietHoursScheduleStore struct {GetFn func(ctxcontext.Context, dbdatabase.Store, userIDuuid.UUID) (UserQuietHoursScheduleOptions,error)SetFn func(ctxcontext.Context, dbdatabase.Store, userIDuuid.UUID, schedulestring) (UserQuietHoursScheduleOptions,error)}
typeTemplateAutostartRequirement¶added inv2.3.1
type TemplateAutostartRequirement struct {// DaysOfWeek is a bitmap of which days of the week the workspace is allowed// to be auto started. If fully zero, the workspace is not allowed to be auto started.//// First bit is Monday, ..., seventh bit is Sunday, eighth bit is unused.DaysOfWeekuint8}
typeTemplateAutostopRequirement¶added inv2.1.5
type TemplateAutostopRequirement struct {// DaysOfWeek is a bitmap of which days of the week the workspace must be// restarted. If fully zero, the workspace is not required to be restarted// ever.//// First bit is Monday, ..., seventh bit is Sunday, eighth bit is unused.DaysOfWeekuint8// Weeks is the amount of weeks between restarts. If 0 or 1, the workspace// is restarted weekly in accordance with DaysOfWeek. If 2, the workspace is// restarted every other week. And so forth.//// The limit for this value is 16, which is roughly 4 months.//// The "first week" starts on January 2nd, 2023, which is the first Monday// of 2023. All other weeks are counted using modulo arithmetic from that// date.Weeksint64}
typeTemplateScheduleOptions¶
type TemplateScheduleOptions struct {UserAutostartEnabledboolUserAutostopEnabledboolDefaultTTLtime.Duration// ActivityBump dictates the duration to bump the workspace's deadline by if// Coder detects activity from the user. A value of 0 means no bumping.ActivityBumptime.Duration// AutostopRequirement dictates when the workspace must be restarted. This// used to be handled by MaxTTL.AutostopRequirementTemplateAutostopRequirement// AutostartRequirement dictates when the workspace can be auto started.AutostartRequirementTemplateAutostartRequirement// FailureTTL dictates the duration after which failed workspaces will be// stopped automatically.FailureTTLtime.Duration// TimeTilDormant dictates the duration after which inactive workspaces will// go dormant.TimeTilDormanttime.Duration// TimeTilDormantAutoDelete dictates the duration after which dormant workspaces will be// permanently deleted.TimeTilDormantAutoDeletetime.Duration// UpdateWorkspaceLastUsedAt updates the template's workspaces'// last_used_at field. This is useful for preventing updates to the// templates inactivity_ttl immediately triggering a dormant action against// workspaces whose last_used_at field violates the new template// inactivity_ttl threshold.UpdateWorkspaceLastUsedAt func(ctxcontext.Context, dbdatabase.Store, templateIDuuid.UUID, lastUsedAttime.Time)error `json:"update_workspace_last_used_at"`// UpdateWorkspaceDormantAt updates the template's workspaces'// dormant_at field. This is useful for preventing updates to the// templates locked_ttl immediately triggering a delete action against// workspaces whose dormant_at field violates the new template time_til_dormant_autodelete// threshold.UpdateWorkspaceDormantAtbool}
typeTemplateScheduleStore¶
type TemplateScheduleStore interface {Get(ctxcontext.Context, dbdatabase.Store, templateIDuuid.UUID) (TemplateScheduleOptions,error)Set(ctxcontext.Context, dbdatabase.Store, templatedatabase.Template, optsTemplateScheduleOptions) (database.Template,error)}
TemplateScheduleStore provides an interface for retrieving templatescheduling options set by the template/site admin.
funcNewAGPLTemplateScheduleStore¶
func NewAGPLTemplateScheduleStore()TemplateScheduleStore
typeUserQuietHoursScheduleOptions¶
type UserQuietHoursScheduleOptions struct {// Schedule is the cron schedule to use for quiet hours windows for all// workspaces owned by the user.//// This value will be set to the parsed custom schedule of the user. If the// user doesn't have a custom schedule set, it will be set to the default// schedule (and UserSet will be false). If quiet hours schedules are not// entitled or disabled instance-wide, this value will be nil to denote that// quiet hours windows should not be used.Schedule *cron.Schedule// UserSet is true if the user has set a custom schedule, false if the// default schedule is being used.UserSetbool// UserCanSet is true if the user is allowed to set a custom schedule. If// false, the user cannot set a custom schedule and the default schedule// will always be used.UserCanSetbool}
typeUserQuietHoursScheduleStore¶
type UserQuietHoursScheduleStore interface {// Get retrieves the quiet hours schedule for the given user. If the user// has not set a custom schedule, the default schedule will be returned. If// quiet hours schedules are not entitled or disabled instance-wide, this// will return a nil schedule.Get(ctxcontext.Context, dbdatabase.Store, userIDuuid.UUID) (UserQuietHoursScheduleOptions,error)// Set sets the quiet hours schedule for the given user. If the given// schedule is an empty string, the user's custom schedule will be cleared// and the default schedule will be used from now on. If quiet hours// schedules are not entitled or disabled instance-wide, this will do// nothing and return a nil schedule.Set(ctxcontext.Context, dbdatabase.Store, userIDuuid.UUID, rawSchedulestring) (UserQuietHoursScheduleOptions,error)}
funcNewAGPLUserQuietHoursScheduleStore¶
func NewAGPLUserQuietHoursScheduleStore()UserQuietHoursScheduleStore