Movatterモバイル変換


[0]ホーム

URL:


Alert GO-2024-3228: Coder vulnerable to post-auth URL redirection to untrusted site ('Open Redirect') in github.com/coder/coder
Notice  The highest tagged major version isv2.

schedule

package
v0.27.3Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License:AGPL-3.0Imports:8Imported by:0

Details

Repository

github.com/coder/coder

Links

Documentation

Overview

package schedule provides utilities for managing template and workspaceautostart and autostop schedules. This includes utilities for parsing anddeserializing cron-style expressions.

Index

Constants

View Source
const MaxTemplateRestartRequirementWeeks = 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.

Functions

funcGetMondayOfWeekadded inv0.26.2

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

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

funcGetNextApplicableMondayOfNWeeksadded inv0.26.2

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.

funcTemplateRestartRequirementEpochadded inv0.26.2

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

funcVerifyTemplateRestartRequirementadded inv0.26.2

func VerifyTemplateRestartRequirement(daysuint8, weeksint64)error

VerifyTemplateRestartRequirement returns an error if the restart requirementis invalid.

funcWeeksSinceEpochadded inv0.26.2

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

typeAutostopTimeadded inv0.26.2

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}

funcCalculateAutostopadded inv0.26.2

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 "restartrequirement" 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.

typeCalculateAutostopParamsadded inv0.26.2

type CalculateAutostopParams struct {Databasedatabase.StoreTemplateScheduleStoreTemplateScheduleStoreUserQuietHoursScheduleStoreUserQuietHoursScheduleStoreNowtime.TimeWorkspacedatabase.Workspace}

typeMockTemplateScheduleStoreadded inv0.22.0

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)Getadded inv0.26.2

func (MockTemplateScheduleStore)Setadded inv0.26.2

typeMockUserQuietHoursScheduleStoreadded inv0.26.2

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)Getadded inv0.26.2

func (MockUserQuietHoursScheduleStore)Setadded inv0.26.2

typeSchedule

type Schedule struct {// contains filtered or unexported fields}

Schedule represents a cron schedule.It's essentially a wrapper for robfig/cron/v3 that has additionalconvenience methods.

funcDailyadded inv0.26.2

func Daily(rawstring) (*Schedule,error)

Daily parses a Schedule from spec scoped to a recurring daily event.Spec consists of the following space-delimited fields, in the following order:- timezone e.g. CRON_TZ=US/Central (optional)- minutes of hour e.g. 30 (required)- hour of day e.g. 9 (required)- day of month (must be *)- month (must be *)- day of week (must be *)

Example Usage:

local_sched, _ := schedule.Weekly("59 23 * * *")fmt.Println(sched.Next(time.Now().Format(time.RFC3339)))// Output: 2022-04-04T23:59:00Zus_sched, _ := schedule.Weekly("CRON_TZ=US/Central 30 9 * * *")fmt.Println(sched.Next(time.Now()).Format(time.RFC3339))// Output: 2022-04-04T14:30:00Z

funcWeekly

func Weekly(rawstring) (*Schedule,error)

Weekly parses a Schedule from spec scoped to a recurring weekly event.Spec consists of the following space-delimited fields, in the following order:- timezone e.g. CRON_TZ=US/Central (optional)- minutes of hour e.g. 30 (required)- hour of day e.g. 9 (required)- day of month (must be *)- month (must be *)- day of week e.g. 1 (required)

Example Usage:

local_sched, _ := schedule.Weekly("59 23 *")fmt.Println(sched.Next(time.Now().Format(time.RFC3339)))// Output: 2022-04-04T23:59:00Zus_sched, _ := schedule.Weekly("CRON_TZ=US/Central 30 9 1-5")fmt.Println(sched.Next(time.Now()).Format(time.RFC3339))// Output: 2022-04-04T14:30:00Z

func (Schedule)Cron

func (sSchedule) Cron()string

Cron returns the cron spec for the schedule with the leading CRON_TZstripped, if present.

func (Schedule)DaysOfWeek

func (sSchedule) DaysOfWeek()string

DaysOfWeek returns a humanized form of the day-of-week field.

func (Schedule)Location

func (sSchedule) Location() *time.Location

Location returns the IANA location for the schedule.

func (Schedule)Min

func (sSchedule) Min()time.Duration

Min returns the minimum duration of the schedule.This is calculated as follows:

  • Let t(0) be a given point in time (1970-01-01T01:01:01Z00:00)
  • Let t(max) be 168 hours after t(0).
  • Let t(1) be the next scheduled time after t(0).
  • Let t(n) be the next scheduled time after t(n-1).
  • Then, the minimum duration of s d(min)= min( t(n) - t(n-1) ∀ n ∈ N, t(n) < t(max) )

func (Schedule)Next

func (sSchedule) Next(ttime.Time)time.Time

Next returns the next time in the schedule relative to t.

func (Schedule)String

func (sSchedule) String()string

String serializes the schedule to its original human-friendly format.The leading CRON_TZ is maintained.

func (Schedule)Time

func (sSchedule) Time()string

Time returns a humanized form of the minute and hour fields.

typeTemplateRestartRequirementadded inv0.26.2

type TemplateRestartRequirement 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 (TemplateRestartRequirement)DaysMapadded inv0.26.2

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

typeTemplateScheduleOptions

type TemplateScheduleOptions struct {UserAutostartEnabledbool          `json:"user_autostart_enabled"`UserAutostopEnabledbool          `json:"user_autostop_enabled"`DefaultTTLtime.Duration `json:"default_ttl"`// TODO(@dean): remove MaxTTL once restart_requirement is matured and the// defaultMaxTTLtime.Duration `json:"max_ttl"`// UseRestartRequirement dictates whether the restart requirement should be// used instead of MaxTTL. This is governed by the feature flag and// licensing.// TODO(@dean): remove this when we remove max_tllUseRestartRequirementbool// RestartRequirement dictates when the workspace must be restarted. This// used to be handled by MaxTTL.RestartRequirementTemplateRestartRequirement `json:"restart_requirement"`// FailureTTL dictates the duration after which failed workspaces will be// stopped automatically.FailureTTLtime.Duration `json:"failure_ttl"`// InactivityTTL dictates the duration after which inactive workspaces will// be locked.InactivityTTLtime.Duration `json:"inactivity_ttl"`// LockedTTL dictates the duration after which locked workspaces will be// permanently deleted.LockedTTLtime.Duration `json:"locked_ttl"`}

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

typeUserQuietHoursScheduleOptionsadded inv0.26.2

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 *ScheduleUserSetbool}

typeUserQuietHoursScheduleStoreadded inv0.26.2

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

funcNewAGPLUserQuietHoursScheduleStoreadded inv0.26.2

func NewAGPLUserQuietHoursScheduleStore()UserQuietHoursScheduleStore

Source Files

View all Source files

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