MCPcopy Create free account
hub / github.com/rilldata/rill / parseScheduleYAML

Method parseScheduleYAML

runtime/parser/parse_partial_schedule.go:26–84  ·  view source on GitHub ↗

parseScheduleYAML parses a ScheduleYAML into a runtimev1.Schedule. The refUpdateDefaultWithCron parameter determines the default value of RefUpdate when a cron schedule is provided but RefUpdate is not explicitly set.

(raw *ScheduleYAML, refUpdateDefaultWithCron bool)

Source from the content-addressed store, hash-verified

24// parseScheduleYAML parses a ScheduleYAML into a runtimev1.Schedule.
25// The refUpdateDefaultWithCron parameter determines the default value of RefUpdate when a cron schedule is provided but RefUpdate is not explicitly set.
26func (p *Parser) parseScheduleYAML(raw *ScheduleYAML, refUpdateDefaultWithCron bool) (*runtimev1.Schedule, error) {
27 // When there's no refresh schedule, default to refreshing on updates to refs.
28 if raw == nil {
29 return &runtimev1.Schedule{RefUpdate: true}, nil
30 }
31
32 // Ignore other settings when "disabled: true"
33 if raw.Disable {
34 return &runtimev1.Schedule{Disable: true}, nil
35 }
36
37 // In dev, unless explicitly enabled, we skip cron/ticker schedules (note that this instead makes ref_update default to true).
38 skipScheduledRefresh := !raw.RunInDev && p.isDev()
39
40 // Prepare the schedule
41 s := &runtimev1.Schedule{}
42
43 // Parse cron
44 if !skipScheduledRefresh && raw.Cron != "" {
45 _, err := cron.ParseStandard(raw.Cron)
46 if err != nil {
47 return nil, fmt.Errorf("invalid cron schedule: %w", err)
48 }
49 s.Cron = raw.Cron
50 }
51
52 // Parse ticker.
53 // NOTE: It probably doesn't make sense to provide both cron and ticker, but we don't enforce that for backwards compatibility.
54 if !skipScheduledRefresh && raw.Every != "" {
55 d, err := parseDuration(raw.Every)
56 if err != nil {
57 return nil, fmt.Errorf("invalid ticker: %w", err)
58 }
59 s.TickerSeconds = uint32(d.Seconds())
60 }
61
62 // Parse time zone
63 if raw.TimeZone != "" {
64 _, err := time.LoadLocation(raw.TimeZone)
65 if err != nil {
66 return nil, fmt.Errorf("invalid time zone: %w", err)
67 }
68 s.TimeZone = raw.TimeZone
69 }
70
71 // Handle ref update.
72 // If not explicitly set, it defaults to true when there is no cron. If there is a cron, the default depends on refUpdateDefaultWithCron.
73 if raw.RefUpdate != nil {
74 s.RefUpdate = *raw.RefUpdate
75 } else {
76 if s.Cron == "" && s.TickerSeconds == 0 {
77 s.RefUpdate = true
78 } else {
79 s.RefUpdate = refUpdateDefaultWithCron
80 }
81 }
82
83 return s, nil

Callers 3

parseReportMethod · 0.95
parseAlertMethod · 0.95
parseModelMethod · 0.95

Calls 3

isDevMethod · 0.95
parseDurationFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected