MCPcopy Create free account
hub / github.com/github/gh-aw / addWeeklyCronWarning

Method addWeeklyCronWarning

pkg/workflow/schedule_preprocessing.go:516–552  ·  view source on GitHub ↗

addWeeklyCronWarning emits a warning when a weekly cron pattern with fixed time is detected

(cronExpr string)

Source from the content-addressed store, hash-verified

514
515// addWeeklyCronWarning emits a warning when a weekly cron pattern with fixed time is detected
516func (c *Compiler) addWeeklyCronWarning(cronExpr string) {
517 // Extract minute, hour, and weekday from the cron expression
518 fields := strings.Fields(cronExpr)
519 if len(fields) >= 5 {
520 minute := fields[0]
521 hour := fields[1]
522 weekday := fields[4]
523 schedulePreprocessingLog.Printf("Warning: detected weekly cron with fixed time: %s", cronExpr)
524
525 // Map weekday number to name for better readability
526 weekdayNames := map[string]string{
527 "0": "Sunday",
528 "1": "Monday",
529 "2": "Tuesday",
530 "3": "Wednesday",
531 "4": "Thursday",
532 "5": "Friday",
533 "6": "Saturday",
534 }
535 weekdayName := weekdayNames[weekday]
536 if weekdayName == "" {
537 weekdayName = "day " + weekday
538 }
539
540 // Construct the warning message
541 warningMsg := fmt.Sprintf(
542 "Schedule uses fixed weekly time (%s %s:%s UTC). Consider using fuzzy schedule 'weekly on %s' instead to distribute workflow execution times and reduce load spikes.",
543 weekdayName, hour, minute, strings.ToLower(weekdayName),
544 )
545
546 // This warning is added to the warning count
547 c.IncrementWarningCount()
548
549 // Store the warning for later display
550 c.addScheduleWarning(warningMsg)
551 }
552}
553
554// addScheduleWarning adds a warning to the compiler's schedule warnings list
555func (c *Compiler) addScheduleWarning(warning string) {

Callers 1

Calls 4

IncrementWarningCountMethod · 0.95
addScheduleWarningMethod · 0.95
ToLowerMethod · 0.80
PrintfMethod · 0.45

Tested by

no test coverage detected