@@ -3,8 +3,12 @@ package workflow
33import (
44 "fmt"
55 "hash/fnv"
6+
7+ "github.com/github/gh-aw/pkg/logger"
68)
79
10+ var maintenanceCronLog = logger .New ("workflow:maintenance_cron" )
11+
812// generateMaintenanceCron generates a cron schedule based on the minimum expires value in days
913// Schedule runs at minimum required frequency to check expirations at appropriate intervals
1014// Returns cron expression and description.
@@ -16,16 +20,20 @@ func generateMaintenanceCron(minExpiresDays int) (string, string) {
1620 // Run at least as often as the shortest expiration would need
1721 if minExpiresDays <= 1 {
1822 // For 1 day or less, run every 2 hours
23+ maintenanceCronLog .Printf ("Selected cron frequency: every 2 hours (minExpiresDays=%d)" , minExpiresDays )
1924 return fmt .Sprintf ("%d */2 * * *" , minute ), "Every 2 hours"
2025 } else if minExpiresDays == 2 {
2126 // For 2 days, run every 6 hours
27+ maintenanceCronLog .Printf ("Selected cron frequency: every 6 hours (minExpiresDays=%d)" , minExpiresDays )
2228 return fmt .Sprintf ("%d */6 * * *" , minute ), "Every 6 hours"
2329 } else if minExpiresDays <= 4 {
2430 // For 3-4 days, run every 12 hours
31+ maintenanceCronLog .Printf ("Selected cron frequency: every 12 hours (minExpiresDays=%d)" , minExpiresDays )
2532 return fmt .Sprintf ("%d */12 * * *" , minute ), "Every 12 hours"
2633 }
2734
2835 // For more than 4 days, run daily
36+ maintenanceCronLog .Printf ("Selected cron frequency: daily (minExpiresDays=%d)" , minExpiresDays )
2937 return fmt .Sprintf ("%d %d * * *" , minute , 0 ), "Daily"
3038}
3139
@@ -48,20 +56,26 @@ func generateSideRepoMaintenanceCron(repoSlug string, minExpiresDays int) (strin
4856 // Derive a deterministic minute in 0-59 from the seed.
4957 minute := int (seed % 60 )
5058
59+ maintenanceCronLog .Printf ("Generating side-repo cron: repoSlug=%q minExpiresDays=%d minute=%d" , repoSlug , minExpiresDays , minute )
60+
5161 if minExpiresDays <= 1 {
5262 // Every 2 hours — vary the starting minute only.
63+ maintenanceCronLog .Printf ("Selected side-repo cron frequency: every 2 hours" )
5364 return fmt .Sprintf ("%d */2 * * *" , minute ), "Every 2 hours"
5465 } else if minExpiresDays == 2 {
5566 // Every 6 hours — vary the starting hour within the 6-hour window.
5667 startHour := int ((seed >> 8 ) % 6 )
68+ maintenanceCronLog .Printf ("Selected side-repo cron frequency: every 6 hours (startHour=%d)" , startHour )
5769 return fmt .Sprintf ("%d %d,%d,%d,%d * * *" , minute , startHour , startHour + 6 , startHour + 12 , startHour + 18 ), "Every 6 hours"
5870 } else if minExpiresDays <= 4 {
5971 // Every 12 hours — vary the starting hour within the 12-hour window.
6072 startHour := int ((seed >> 8 ) % 12 )
73+ maintenanceCronLog .Printf ("Selected side-repo cron frequency: every 12 hours (startHour=%d)" , startHour )
6174 return fmt .Sprintf ("%d %d,%d * * *" , minute , startHour , startHour + 12 ), "Every 12 hours"
6275 }
6376
6477 // Daily — vary the hour of day (0-23) to spread load.
6578 hour := int ((seed >> 8 ) % 24 )
79+ maintenanceCronLog .Printf ("Selected side-repo cron frequency: daily (hour=%d)" , hour )
6680 return fmt .Sprintf ("%d %d * * *" , minute , hour ), "Daily"
6781}
0 commit comments