Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions harnesses/aggregator-head-lag/cmd/script/codex_scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,35 +120,42 @@ func chromeAvailable() bool {
}

// startInProcessScraper launches a background goroutine that refreshes the JWE every 5 min.
// Call once from main. No-ops silently if Chrome is not installed.
// Call once from main. No-ops silently if Chrome is not installed or repeatedly fails.
func startInProcessScraper(stopChan <-chan struct{}) {
if !chromeAvailable() {
fmt.Println("[CODEX-SCRAPER] Chrome not found — in-process scraper disabled (sidecar will be used)")
return
}

go func() {
// Initial delay: let the container fully start before launching Chrome.
select {
case <-stopChan:
return
case <-time.After(10 * time.Second):
}

refreshInterval := 5 * time.Minute
consecutiveFails := 0
const maxFails = 3

for {
fmt.Println("[CODEX-SCRAPER] Scraping defined.fi for fresh JWE...")
tok, err := scrapeCodexToken()
if err != nil {
fmt.Printf("[CODEX-SCRAPER] Scrape failed: %v — retrying in 60s\n", err)
consecutiveFails++
if consecutiveFails >= maxFails {
fmt.Printf("[CODEX-SCRAPER] %d consecutive failures — disabling scraper (sidecar will be used)\n", maxFails)
return
}
fmt.Printf("[CODEX-SCRAPER] Scrape failed (%d/%d): %v — retrying in 60s\n", consecutiveFails, maxFails, err)
select {
case <-stopChan:
return
case <-time.After(60 * time.Second):
continue
}
}
consecutiveFails = 0
setInProcessJWE(tok)
fmt.Printf("[CODEX-SCRAPER] Fresh JWE stored (len=%d), next refresh in %v\n", len(tok), refreshInterval)

Expand Down
Loading