Refactor schedule_parser: split 1163-line file into focused modules#11588
Merged
Refactor schedule_parser: split 1163-line file into focused modules#11588
Conversation
…h tests Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor large Go file pkg/parser/schedule_parser.go
Refactor schedule_parser: split 1163-line file into focused modules
Jan 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pkg/parser/schedule_parser.goexceeded healthy size limits at 1163 lines, mixing cron detection, fuzzy scheduling, time parsing, and parser orchestration in a single file.Changes
Split into three focused modules:
schedule_cron_detection.go (140 lines): Cron pattern detection and validation
IsDailyCron,IsHourlyCron,IsWeeklyCron,IsFuzzyCron,IsCronExpressionschedule_fuzzy_scatter.go (319 lines): Deterministic time distribution for fuzzy schedules
ScatterSchedulewith support for DAILY, HOURLY, WEEKLY, BI_WEEKLY, TRI_WEEKLY patternsstableHashfor consistent workflow time assignmentschedule_time_utils.go (245 lines): Time parsing and conversion utilities
parseTime,parseTimeToMinutes,mapWeekday,parseUTCOffset,parseHourMinuteMain file reduced: 1163 → 512 lines (56% reduction)
Each module includes:
All existing tests pass without modification. Public API unchanged.
Original prompt
This section details on the original issue you should resolve
<issue_title>[file-diet] Refactor Large Go File: pkg/parser/schedule_parser.go (1084 lines)</issue_title>
<issue_description>### Overview
The file
pkg/parser/schedule_parser.gohas grown to 1084 lines, significantly exceeding the healthy 800-line threshold. While it has excellent test coverage (2031 test lines, ~1.87 ratio), the file's size makes it difficult to navigate and maintain. This task involves refactoring it into smaller, focused modules with clear boundaries.Current State
pkg/parser/schedule_parser.goschedule_parser_test.go(~1.87 ratio)Problem Analysis
The file mixes multiple concerns:
ScatterSchedule)Refactoring Strategy
Split the file into focused modules aligned with functional boundaries:
1.
schedule_cron_detection.go(~150 lines)Functions to move:
IsDailyCron(cron string) boolIsHourlyCron(cron string) boolIsWeeklyCron(cron string) boolIsFuzzyCron(cron string) boolIsCronExpression(input string) boolResponsibility: Cron pattern detection and classification
Rationale: These are pure functions that analyze cron strings. They have no dependencies on the parser state and can be tested independently.
2.
schedule_fuzzy_scatter.go(~320 lines)Functions to move:
ScatterSchedule(fuzzyCron, workflowIdentifier string) (string, error)(290+ lines)stableHash(s string, modulo int) intResponsibility: Deterministic fuzzy schedule time distribution
Rationale: The
ScatterSchedulefunction is self-contained with complex logic for different fuzzy patterns (DAILY, HOURLY, WEEKLY, etc.). Extracting it reduces the main file by ~30%.3.
schedule_time_utils.go(~150 lines)Functions to move:
parseTime(timeStr string) (minute string, hour string)(120 lines)parseTimeToMinutes(hourStr, minuteStr string) intmapWeekday(day string) stringResponsibility: Time parsing and conversion utilities
Rationale: These are helper functions used by the parser but don't depend on parser state. Can be reused by other modules.
4.
schedule_parser_core.go(~250 lines)Keep in this file:
ScheduleParserstructParseSchedule(input string) (cron, original, error)(entry point)(p *ScheduleParser) tokenize() error(p *ScheduleParser) parse() (string, error)Responsibility: High-level parsing orchestration
Rationale: This is the main API surface. Keeping it focused on orchestration makes the flow clear.
5.
schedule_parser_expressions.go(~250 lines)Functions to move:
(p *ScheduleParser) parseInterval() (string, error)(150+ lines)(p *ScheduleParser) parseBase() (string, error)(180+ lines)(p *ScheduleParser) extractTime(startPos int) (string, error)(p *ScheduleParser) extractTimeBetween(startPos, endPos int) (string, error)(p *ScheduleParser) extractTimeAfter(startPos int) (string, error)Responsibility: Schedule expression parsing (interval, base, time extraction)
Rationale: These are the detailed parsing methods that consume tokens. They depend on parser state but can be in a separate file via
schedule_parser_core.go.Implementation Plan
Step-by-step refactoring approach
Create test infrastructure first
make test-unitto establish baselineExtract utilities (no dependencies)
schedule_time_utils.gowith time parsing functionsschedule_time_utils_test.gowith relevant testsExtract detection functions
schedule_cron_detection.gowithIs*Cronfunctionsschedule_cron_detection_test.gowith relevant testsExtract fuzzy scattering
schedule_fuzzy_scatter.gowithScatterScheduleandstableHashschedule_fuzzy_scatter_test.gowith relevant testsSplit parser methods
schedule_parser_expressions.gowith parsing methodsparseInterval,parseBase,extractTime*methodsScheduleParserreceiverRename original file
schedule_parser.gotoschedule_parser_core.go💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.