Movatterモバイル変換


[0]ホーム

URL:


schedule

package
v2.23.0Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2025 License:AGPL-3.0Imports:10Imported by:0

Details

Repository

github.com/coder/coder

Links

Documentation

Index

Constants

View Source
const MaxTemplateAutostopRequirementWeeks = 16

Variables

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.

View Source
var ErrNoAllowedAutostart =xerrors.New("no allowed autostart")
View Source
var ErrUserCannotSetQuietHoursSchedule =xerrors.New("user cannot set custom quiet hours schedule due to deployment configuration")

Functions

funcGetMondayOfWeek

func GetMondayOfWeek(loc *time.Location, nint64) (time.Time,error)

GetMondayOfWeek gets the Monday (0:00) of the n-th week since epoch.

funcGetNextApplicableMondayOfNWeeks

func GetNextApplicableMondayOfNWeeks(nowtime.Time, nint64) (time.Time,error)

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.

funcNextAllowedAutostartadded inv2.19.0

func NextAllowedAutostart(attime.Time, wsSchedulestring, templateScheduleTemplateScheduleOptions) (time.Time,error)

funcNextAutostartadded 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.

funcTemplateAutostopRequirementEpochadded inv2.1.5

func TemplateAutostopRequirementEpoch(loc *time.Location)time.Time

funcVerifyTemplateAutostartRequirementadded inv2.3.1

func VerifyTemplateAutostartRequirement(daysuint8)error

VerifyTemplateAutostartRequirement returns an error if the autostartrequirement is invalid.

funcVerifyTemplateAutostopRequirementadded inv2.1.5

func VerifyTemplateAutostopRequirement(daysuint8, weeksint64)error

VerifyTemplateAutostopRequirement returns an error if the autostoprequirement is invalid.

funcWeeksSinceEpoch

func WeeksSinceEpoch(nowtime.Time) (int64,error)

WeeksSinceEpoch gets the weeks since the epoch for a given time. This is a0-indexed number of weeks since the epoch (Monday).

The timezone embedded in the time object is used to determine the epoch.

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)}

func (MockTemplateScheduleStore)Get

func (MockTemplateScheduleStore)Set

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)}

func (MockUserQuietHoursScheduleStore)Get

func (MockUserQuietHoursScheduleStore)Set

typeTemplateAutostartRequirementadded 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}

func (TemplateAutostartRequirement)DaysMapadded inv2.3.1

typeTemplateAutostopRequirementadded 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}

func (TemplateAutostopRequirement)DaysMapadded inv2.1.5

DaysMap returns a map of the days of the week that the workspace must berestarted.

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

Source Files

View all Source files

Directories

PathSynopsis
package schedule provides utilities for managing template and workspace autostart and autostop schedules.
package schedule provides utilities for managing template and workspace autostart and autostop schedules.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp