- commit
- 2601552
- parent
- 07f1a61
- author
- Antonio Mika
- date
- 2024-11-18 14:32:16 +0000 UTC
Fix metric drain
1 files changed,
+23,
-17
+23,
-17
1@@ -651,27 +651,33 @@ func metricDrainSub(ctx context.Context, dbpool db.DB, logger *slog.Logger, secr
2 10*time.Millisecond,
3 )
4
5- scanner := bufio.NewScanner(drain)
6- for scanner.Scan() {
7- line := scanner.Text()
8- visit := db.AnalyticsVisits{}
9- err := json.Unmarshal([]byte(line), &visit)
10- if err != nil {
11- logger.Error("json unmarshal", "err", err)
12- continue
13- }
14+ for {
15+ scanner := bufio.NewScanner(drain)
16+ for scanner.Scan() {
17+ line := scanner.Text()
18+ visit := db.AnalyticsVisits{}
19+ err := json.Unmarshal([]byte(line), &visit)
20+ if err != nil {
21+ logger.Error("json unmarshal", "err", err)
22+ continue
23+ }
24
25- err = shared.AnalyticsVisitFromVisit(&visit, dbpool, secret)
26- if err != nil {
27- if !errors.Is(err, shared.ErrAnalyticsDisabled) {
28- logger.Info("could not record analytics visit", "reason", err)
29+ err = shared.AnalyticsVisitFromVisit(&visit, dbpool, secret)
30+ if err != nil {
31+ if !errors.Is(err, shared.ErrAnalyticsDisabled) {
32+ logger.Info("could not record analytics visit", "reason", err)
33+ }
34+ }
35+
36+ logger.Info("inserting visit", "visit", visit)
37+ err = dbpool.InsertVisit(&visit)
38+ if err != nil {
39+ logger.Error("could not insert visit record", "err", err)
40 }
41 }
42
43- logger.Info("inserting visit", "visit", visit)
44- err = dbpool.InsertVisit(&visit)
45- if err != nil {
46- logger.Error("could not insert visit record", "err", err)
47+ if scanner.Err() != nil {
48+ logger.Error("scanner error", "err", scanner.Err())
49 }
50 }
51 }