Documentation ¶
Overview ¶
package schedule provides utilities for managing template and workspace autostart and autostop schedules. This includes utilities for parsing and deserializing cron-style expressions.
Index ¶
- type MockTemplateScheduleStore
- func (m MockTemplateScheduleStore) GetTemplateScheduleOptions(ctx context.Context, db database.Store, templateID uuid.UUID) (TemplateScheduleOptions, error)
- func (m MockTemplateScheduleStore) SetTemplateScheduleOptions(ctx context.Context, db database.Store, template database.Template, ...) (database.Template, error)
- type Schedule
- type TemplateScheduleOptions
- type TemplateScheduleStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockTemplateScheduleStore ¶ added in v0.22.0
type MockTemplateScheduleStore struct { GetFn func(ctx context.Context, db database.Store, templateID uuid.UUID) (TemplateScheduleOptions, error) SetFn func(ctx context.Context, db database.Store, template database.Template, options TemplateScheduleOptions) (database.Template, error) }
func (MockTemplateScheduleStore) GetTemplateScheduleOptions ¶ added in v0.22.0
func (m MockTemplateScheduleStore) GetTemplateScheduleOptions(ctx context.Context, db database.Store, templateID uuid.UUID) (TemplateScheduleOptions, error)
func (MockTemplateScheduleStore) SetTemplateScheduleOptions ¶ added in v0.22.0
type Schedule ¶
type Schedule struct {
// contains filtered or unexported fields
}
Schedule represents a cron schedule. It's essentially a wrapper for robfig/cron/v3 that has additional convenience methods.
func Weekly ¶
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:00Z us_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 ¶
Cron returns the cron spec for the schedule with the leading CRON_TZ stripped, if present.
func (Schedule) DaysOfWeek ¶
DaysOfWeek returns a humanized form of the day-of-week field.
func (Schedule) Min ¶
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) )
type TemplateScheduleOptions ¶
type TemplateScheduleOptions struct { UserAutostartEnabled bool `json:"user_autostart_enabled"` UserAutostopEnabled bool `json:"user_autostop_enabled"` DefaultTTL time.Duration `json:"default_ttl"` // If MaxTTL is set, the workspace must be stopped before this time or it // will be stopped automatically. // // If set, users cannot disable automatic workspace shutdown. MaxTTL time.Duration `json:"max_ttl"` // If FailureTTL is set, all failed workspaces will be stopped automatically after this time has elapsed. FailureTTL time.Duration `json:"failure_ttl"` // If InactivityTTL is set, all inactive workspaces will be deleted automatically after this time has elapsed. InactivityTTL time.Duration `json:"inactivity_ttl"` }
type TemplateScheduleStore ¶
type TemplateScheduleStore interface { GetTemplateScheduleOptions(ctx context.Context, db database.Store, templateID uuid.UUID) (TemplateScheduleOptions, error) SetTemplateScheduleOptions(ctx context.Context, db database.Store, template database.Template, opts TemplateScheduleOptions) (database.Template, error) }
TemplateScheduleStore provides an interface for retrieving template scheduling options set by the template/site admin.
func NewAGPLTemplateScheduleStore ¶
func NewAGPLTemplateScheduleStore() TemplateScheduleStore