diff --git a/cmd/badges/main.go b/cmd/badges/main.go index 200f5dda..2cdeecf0 100644 --- a/cmd/badges/main.go +++ b/cmd/badges/main.go @@ -13,6 +13,7 @@ import ( "regexp" "strconv" "strings" + "sync" "time" "github.com/boyter/scc/v3/processor" @@ -30,6 +31,8 @@ var ( countingSemaphore = make(chan bool, 1) tmpDir = os.TempDir() json = jsoniter.ConfigCompatibleWithStandardLibrary + locationLog = []string{} + locationLogMutex = sync.Mutex{} ) func intPtr(i int) *int { @@ -41,6 +44,14 @@ func timePtr(t time.Duration) *time.Duration { } func main() { + http.HandleFunc("/health-check/", func(w http.ResponseWriter, r *http.Request) { + locationLogMutex.Lock() + for _, l := range locationLog { + _, _ = w.Write([]byte(l + "\n")) + } + locationLogMutex.Unlock() + }) + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { loc, err := processUrlPath(r.URL.Path) if err != nil { @@ -49,6 +60,8 @@ func main() { return } + appendLocationLog(loc.String()) + res, err := process(1, loc) if err != nil { log.Error().Str(uniqueCode, "03ec75c3").Err(err).Str("loc", loc.String()).Send() @@ -87,6 +100,17 @@ func main() { } } +func appendLocationLog(log string) { + locationLogMutex.Lock() + defer locationLogMutex.Unlock() + + locationLog = append(locationLog, log) + + if len(locationLog) > 100 { + locationLog = locationLog[1:] + } +} + func calculate(category string, wage int, res []processor.LanguageSummary) (string, int64) { title := "" var value int64