improved logging for debug

This commit is contained in:
2026-05-16 11:44:35 +01:00
parent c110a2cc70
commit 24c2814eef
3 changed files with 54 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"time"
"github.com/shopspring/decimal"
@@ -58,10 +59,21 @@ type Selector func(Record) bool
func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter, s Selector) error {
buys := make(map[string]*FillerQueue)
var buysCount, sellsCount int64
var lastTimestamp time.Time
progTicker := time.NewTicker(10 * time.Second)
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-progTicker.C:
slog.InfoContext(ctx, "Progress update",
slog.Int64("total_records", buysCount+sellsCount),
slog.Int64("sell_records", sellsCount),
slog.Int64("buy_records", buysCount),
slog.Time("last_record_timestamp", lastTimestamp),
)
default:
rec, err := reader.ReadRecord(ctx)
if err != nil {
@@ -72,9 +84,21 @@ func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter,
}
if !s(rec) {
slog.Debug("Report: skipping record",
slog.String("symbol", rec.Symbol()),
slog.String("side", rec.Side().String()),
)
continue
}
if rec.Side().IsBuy() {
buysCount++
} else {
sellsCount++
}
lastTimestamp = rec.Timestamp()
buyQueue, ok := buys[rec.Symbol()]
if !ok {
buyQueue = new(FillerQueue)
@@ -85,11 +109,17 @@ func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter,
if err != nil {
return fmt.Errorf("processing record: %w", err)
}
}
}
}
func processRecord(ctx context.Context, q *FillerQueue, rec Record, writer ReportWriter) error {
slog.Debug("Report: processing record",
slog.String("symbol", rec.Symbol()),
slog.String("side", rec.Side().String()),
)
switch rec.Side() {
case SideBuy:
q.Push(NewFiller(rec))