Skip to content

Commit

Permalink
add log for badges
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Jan 15, 2025
1 parent 6f80983 commit 77a63c5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmd/badges/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"time"

"github.com/boyter/scc/v3/processor"
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 77a63c5

Please sign in to comment.