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

Method processStopAfterConfiguration

pkg/workflow/stop_after.go:54–112  ·  view source on GitHub ↗

processStopAfterConfiguration extracts and processes stop-after configuration from frontmatter

(frontmatter map[string]any, workflowData *WorkflowData, markdownPath string)

Source from the content-addressed store, hash-verified

52
53// processStopAfterConfiguration extracts and processes stop-after configuration from frontmatter
54func (c *Compiler) processStopAfterConfiguration(frontmatter map[string]any, workflowData *WorkflowData, markdownPath string) error {
55 stopAfterLog.Printf("Processing stop-after configuration for workflow: %s", markdownPath)
56 // Extract stop-after from the on: section
57 stopAfter, err := c.extractStopAfterFromOn(frontmatter, workflowData)
58 if err != nil {
59 return err
60 }
61 workflowData.StopTime = stopAfter
62
63 // Resolve relative stop-after to absolute time if needed
64 if workflowData.StopTime != "" {
65 stopAfterLog.Printf("Stop-after value specified: %s", workflowData.StopTime)
66 // Check if there's already a lock file with a stop time (recompilation case)
67 lockFile := stringutil.MarkdownToLockFile(markdownPath)
68 existingStopTime := ExtractStopTimeFromLockFile(lockFile)
69
70 // If refresh flag is set, always regenerate the stop time
71 if c.refreshStopTime {
72 stopAfterLog.Print("Refresh flag set, regenerating stop time")
73 resolvedStopTime, err := resolveStopTime(workflowData.StopTime, time.Now().UTC())
74 if err != nil {
75 return fmt.Errorf("invalid stop-after format: %w", err)
76 }
77 originalStopTime := stopAfter
78 workflowData.StopTime = resolvedStopTime
79 stopAfterLog.Printf("Resolved stop time from %s to %s", originalStopTime, resolvedStopTime)
80
81 if c.verbose && isRelativeStopTime(originalStopTime) {
82 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Refreshed relative stop-after to: "+resolvedStopTime))
83 } else if c.verbose && originalStopTime != resolvedStopTime {
84 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Refreshed absolute stop-after from '%s' to: %s", originalStopTime, resolvedStopTime)))
85 }
86 } else if existingStopTime != "" {
87 // Preserve existing stop time during recompilation (default behavior)
88 stopAfterLog.Printf("Preserving existing stop time from lock file: %s", existingStopTime)
89 workflowData.StopTime = existingStopTime
90 if c.verbose {
91 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Preserving existing stop time from lock file: "+existingStopTime))
92 }
93 } else {
94 // First compilation or no existing stop time, generate new one
95 stopAfterLog.Print("First compilation, generating new stop time")
96 resolvedStopTime, err := resolveStopTime(workflowData.StopTime, time.Now().UTC())
97 if err != nil {
98 return fmt.Errorf("invalid stop-after format: %w", err)
99 }
100 originalStopTime := stopAfter
101 workflowData.StopTime = resolvedStopTime
102
103 if c.verbose && isRelativeStopTime(originalStopTime) {
104 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Resolved relative stop-after to: "+resolvedStopTime))
105 } else if c.verbose && originalStopTime != resolvedStopTime {
106 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Parsed absolute stop-after from '%s' to: %s", originalStopTime, resolvedStopTime)))
107 }
108 }
109 }
110
111 return nil

Callers 2

Calls 9

MarkdownToLockFileFunction · 0.92
FormatInfoMessageFunction · 0.92
resolveStopTimeFunction · 0.85
isRelativeStopTimeFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 1