classifyScheduleFrequency determines which standard frequency a schedule expression represents. Returns one of: "hourly", "3-hourly", "daily", "weekly", "monthly", or "custom".
(scheduleStr string)
| 128 | // classifyScheduleFrequency determines which standard frequency a schedule expression represents. |
| 129 | // Returns one of: "hourly", "3-hourly", "daily", "weekly", "monthly", or "custom". |
| 130 | func classifyScheduleFrequency(scheduleStr string) string { |
| 131 | normalized := strings.ToLower(strings.TrimSpace(scheduleStr)) |
| 132 | |
| 133 | // Direct friendly-format matches |
| 134 | switch normalized { |
| 135 | case "hourly", "every 1h", "every 1 hour", "every 1 hours": |
| 136 | return "hourly" |
| 137 | case "every 3h", "every 3 hours": |
| 138 | return "3-hourly" |
| 139 | case "daily": |
| 140 | return "daily" |
| 141 | case "weekly": |
| 142 | return "weekly" |
| 143 | } |
| 144 | |
| 145 | // Fuzzy cron placeholder matches (produced by the compiler during preprocessing) |
| 146 | if strings.HasPrefix(normalized, "fuzzy:hourly/1 ") || normalized == "fuzzy:hourly/1" { //nolint:tolowerequalfold |
| 147 | return "hourly" |
| 148 | } |
| 149 | if strings.HasPrefix(normalized, "fuzzy:hourly/3 ") || normalized == "fuzzy:hourly/3" { //nolint:tolowerequalfold |
| 150 | return "3-hourly" |
| 151 | } |
| 152 | if strings.HasPrefix(normalized, "fuzzy:daily") { |
| 153 | return "daily" |
| 154 | } |
| 155 | if strings.HasPrefix(normalized, "fuzzy:weekly") { |
| 156 | return "weekly" |
| 157 | } |
| 158 | |
| 159 | // Cron expression checks |
| 160 | if parser.IsHourlyCron(scheduleStr) { |
| 161 | fields := strings.Fields(scheduleStr) |
| 162 | if len(fields) == 5 { |
| 163 | interval := strings.TrimPrefix(fields[1], "*/") |
| 164 | switch interval { |
| 165 | case "1": |
| 166 | return "hourly" |
| 167 | case "3": |
| 168 | return "3-hourly" |
| 169 | } |
| 170 | } |
| 171 | return "custom" |
| 172 | } |
| 173 | |
| 174 | if parser.IsDailyCron(scheduleStr) { |
| 175 | return "daily" |
| 176 | } |
| 177 | |
| 178 | if parser.IsWeeklyCron(scheduleStr) { |
| 179 | return "weekly" |
| 180 | } |
| 181 | |
| 182 | // Monthly cron: M H <day> * * where <day> is a specific numeric date (e.g. "1", "15"). |
| 183 | // fields: [0]=minute [1]=hour [2]=day-of-month [3]=month [4]=day-of-week |
| 184 | // Excludes interval expressions like "*/2" so that "0 0 */2 * *" (every-2-days) is |
| 185 | // correctly classified as "custom" rather than "monthly". |
| 186 | fields := strings.Fields(scheduleStr) |
| 187 | if len(fields) == 5 && fields[3] == "*" && fields[4] == "*" { |